Skip to content

Conversation

@JohnoKing
Copy link

This pull request adds the ${$var} feature from ksh93v-. It allows for indirect expansion of $var, such that if var is set to 'foo', ${$var} expands to ${foo}. Example:

$ var=foo
$ foo='Intended result'
$ echo ${$var}
Intended result

src/cmd/ksh93/sh.1,
src/cmd/ksh93/sh/lex.c,
src/cmd/ksh93/sh/macro.c:

  • Backport indirect variable name expansion from ksh93v-.
  • When the parameter is unset, set the type to M_BRACE ala ${@var}. This fixes a ksh93v- bug that could cause ${$bar:0:1} to produce the string '00:1}' when bar is not set.
  • If v is NULL, avoid nv_open and simply set np to NULL.
  • Cope with invalid results from strtol.

src/cmd/ksh93/tests/variables.sh:

  • Backport a ksh93v- regression test alteration to account for ${$var} now being valid syntax. The test now tries ${$$}, which is invalid syntax in all ksh93 releases.
  • Add regression tests for ${$var} indirect expansion (some are backports and some are new).

This patch was stalled for a comically long time because the ksh93v- code had bugs that needed squashing (I've been using various iterations of it since 2021). In any case, this'll be my first 2026 submission to add to the pile of pull requests (I have many more patches, of course).

This patch adds the ${$var} feature from ksh93v-. It allows for
indirect expansion of $var, such that if var is set to foo,
${$var} expands to ${foo}. Example:
    $ var=foo
    $ foo='Intended result'
    $ echo ${$var}
    Intended result

This patch was stalled for a comically long time because the
ksh93v- code had bugs that needed squashing (I've been using various
iterations of it since 2021).

src/cmd/ksh93/sh.1,
src/cmd/ksh93/sh/lex.c,
src/cmd/ksh93/sh/macro.c:
- Backport indirect variable name expansion from ksh93v-.
- When the parameter is unset, set the type to M_BRACE ala ${@var}.
  This fixes a ksh93v- bug that could cause ${$bar:0:1} to
  produce the string '00:1}' when bar is not set.
- If v is NULL, avoid nv_open and simply set np to NULL.
- Cope with invalid results from strtol.

src/cmd/ksh93/tests/variables.sh:
- Backport a ksh93v- regression test alteration to account for
  ${$var} now being valid syntax. The test now tries ${$$}, which
  is invalid syntax in all ksh93 releases.
- Add regression tests for ${$var} indirect expansion (some are
  backports and some are new).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant