On Thu, 10 Jul 2025 at 01:36, Chet Ramey <chet.ra...@case.edu> wrote:
> If the expression hadn't contained $x, nothing would have been expanded, > because expanding a word without any expansion characters is a waste of > time. This arguably causes a problem in this case; it would have been > more consistent to run the whole string through word expansion and quote > the subscript in all cases. > Or alternatively, always defer expansions, so that such generated quoting is unnecessary. It's all very well to say "leave out the '$'", but that can't work when the key for a hash itself has to be computed. Compare: $ declare -A hash=() foo=( [bar]=4 ) ; declare -a keys=( [0]=humbug [4]=hokeypokey ) $ i= ; (( i=foo[bar], hash[${keys[i]}]++ )) $ declare -p hash declare -A hash=([*humbug*]="1" ) $ declare -A hash=() foo=( [bar]=4 ) ; declare -a keys=( [0]=humbug [4]=hokeypokey ) $ i= ; (( hash[${keys[i=foo[bar]]}]++ )) $ declare -p hash declare -A hash=([*hokeypokey*]="1" ) Advanced users hopefully understand that there are two numeric contexts that are evaluated at different times, despite being apparently nested one within the other, but it's hardly obvious to a new user, even after they've read the manual. It would be more useful - and less confusing - if both produced the second answer. Sure, this wouldn't be exactly compatible with previous behaviour, but then neither is the current behaviour. -Martin