Backport support for ${$var} indirection from ksh93v-#931
Open
Backport support for ${$var} indirection from ksh93v-#931
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds the
${$var}feature from ksh93v-. It allows for indirect expansion of$var, such that ifvaris set to 'foo',${$var}expands to${foo}. Example:src/cmd/ksh93/sh.1,
src/cmd/ksh93/sh/lex.c,
src/cmd/ksh93/sh/macro.c:
M_BRACEala${@var}. This fixes a ksh93v- bug that could cause${$bar:0:1}to produce the string '00:1}' whenbaris not set.nv_openand simply set np to NULL.strtol.src/cmd/ksh93/tests/variables.sh:
${$var}now being valid syntax. The test now tries${$$}, which is invalid syntax in all ksh93 releases.${$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).