bug-bash
[Top][All Lists]
Advanced

[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
<http://localhost:8080/Go/Package/GoFile/examples/var-lists/@var:try-duplicate-names>'
I have this code to extract the text between '@' and ':' into variable key:

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

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

            key="${{file#@}%:*}"

Or, without using an intermediate variable:

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

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

-- 
Ken Irving


reply via email to

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