[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Suggestion for nesting multiple parameter expansions as ${{param..}...}

From: Kenneth Irving
Subject: Suggestion for nesting multiple parameter expansions as ${{param..}...}
Date: Thu, 11 Nov 2021 13:51:37 -0900

Not a bug, but a suggestion...  Given a file like '@var:try-duplicate-names
I have this code to extract the text between '@' and ':' into variable key:

       for file in "${files[@]}"; do
            readListFile "$key" "$file" ""

An alternative syntax to do multiple expansions on a single parameter might


Or, without using an intermediate variable:

       for file in "${files[@]}"; do
            readListFile "${{file#@}%:*}" "$file" ""

I think this proposed syntax might be easy to parse, and probably doesn't
conflict with existing valid bash syntax.  Other shells may take another
approach, e.g. I guess zsh allows nesting whole parameter expansion
sequences, like ${${file#@}%:*}, but I think with the proposed syntax it is
clearer to see what's going on.  In either case (this proposal or
zsh's syntax) the parameter name just has to appear once, vs one time for
each expansion in current bash; the repetition of parameter names has been
a source of bugs in some of my code in the past where multiple expansions
were needed on a single parameter.

For the record, I'm running this version of bash:

GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0)
installed using homebrew probably years ago on a MacOS laptop, where
the default bash is quite a bit older:

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20)


Ken Irving

reply via email to

[Prev in Thread] Current Thread [Next in Thread]