Re: feature request: ${[@]| command; } and ${[*]| command; } funsubs to expand to all elements of the local array REPLY
Koichi Murase <[email protected]> Tue, 7 Apr 2026 09:25:57 +0900
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <CAFLRLk_z1vtWDg=gYMdTTOn8ba6Oagp6N=4zK6nZtoRSwkENFw@mail.gmail.com> |
2026年4月7日(火) 5:37 Zachary Santer <[email protected]>: > declare -a array=( > "${[@]| this_function args...; }" > ) > > this_function has no way to set REPLY as an associative array. > > [...] > > So allowing ${[@]| command; } to work for either an indexed or an > associative array would still force the user to do something a little > awkward to get it to work for an associative array, and it probably > wouldn't be used very often with one. Is there even a single case where it's useful? I think the most reasonable behavior in the case of an associative-array REPLY is to expand values of the associative array, just like "${REPLY[@]}" would produce only values. Then, keys are always lost. Instead, it is much simpler to store only values to REPLY as an indexed array from the beginning. Or one may further add the syntax ${![@]| this_function; } to extract the keys with the same "this_function", but the values are always lost with this syntax. When using a function returning an associative array, I think we want to get the keys and values at the same time in most cases. Furthermore, it would be desirable to reconstruct an associative array at the caller scope. Then, I think one finally needs to rely on an indexed-array REPLY as this_function() { declare -A result=(...) REPLY=("${result[@]@k}") } declare -A myassoc=("${@| this_function; }") -- Koichi