Re: ="${!a[@]}" expands incorrectly bash 5.1 and above + patch
From:
Chet Ramey
Subject:
Re: ="${!a[@]}" expands incorrectly bash 5.1 and above + patch
Date:
Fri, 29 May 2026 16:53:01 -0400
User-agent:
Mozilla Thunderbird
On 5/24/26 5:31 AM, Emanuele Torre wrote:
The current order of these cases does not seem logical to me; it is
probably incorrect: I would expect the PF_ASSIGNRHS case not to care
about whether the expansion is quoted, and thus also to take precedence
over the case for double quoted expansions outside of assignments.
Thanks for the report.
The question is consistency: does quoted $@ in a context where word
splitting doesn't take place behave the same as unquoted $@, or does
it behave like quoted $*? (This only makes a difference when IFS is
not the default, so it's a niche case.)
There was a pretty decent discussion about this in the replies to your
message from last November that you reference later; kre points out
that the behavior of all of this is unspecified, and there are two
camps, one for each interpretation.
Unless I am missing something, reordering those two cases seems to fix
the regression; so, the fix probably looks similar to something like
this:
You didn't run the test suite, did you.
Anyway, I agree with you: it's better to have consistent behavior between
quoted and unquoted $@ in a context where word splitting doesn't take
place, than to have quoted $@ and $* behave the same.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/