feature request: ${[@]| command; } and ${[*]| command; } funsubs to expand to all elements of the local array REPLY
Zachary Santer <[email protected]> Thu, 2 Apr 2026 12:15:12 -0400
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <CABkLJUJqWEuysrKOEFakBqMqpd8eKiA_53bR9JMnYMBzkToN8Q@mail.gmail.com> |
Was "feature request: ${@ command; } and ${* command; } funsubs to
expand to all elements of the local array REPLY," obviously.
On Thu, Apr 2, 2026 at 5:24 AM Koichi Murase <[email protected]> wrote:
>
> I chose ${@| cmd; } so that it is distinct from
> ${<word> cmd; } to keep it for future extension.
Another way to look at ${@| cmd; } is that any time a REPLY local
variable is created and referenced, there's a | involved. And when
you're reading from stdin, there isn't. I actually prefer this over
${@ cmd; }. ${[@]| cmd; } would be another option. This might be a bit
more idiomatic, since this is referencing an array, rather than any
positional parameters. It could also be extended to specify one
element of the REPLY array.
$ printf '%s\n' "${[2]| REPLY=( zero one two three ); }"
two
And then you could have ${[*]| cmd; }, if that would serve a purpose.
No way to turn it around to look maybe a little bit more like a
reference to an array element, because the ${|cmd; } form allows cmd
to follow the | immediately.
$ [@] () { REPLY="square brackets ${1}"
$ printf '%s\n' "${|[@] foo; }"
square brackets foo
Zack