On Wed, Jul 09, 2025 at 11:36:59 -0400, Chet Ramey wrote: > The arithmetic expression within (( and )) is equivalent to > > let "expression" > > so the contents are expanded once as if in double quotes. This has > always been the case -- earlier versions of bash just translated > ((expr)) into let "expr" internally, and the documentation was explicit > about the equivalence.
If that's true, then I don't understand why these two commands give different results: (( hash[\$key]++ )) let "hash[\$key]++" hobbit:~$ echo "$BASH_VERSION" 5.3.0(1)-release hobbit:~$ unset hash hobbit:~$ declare -A hash; key=\'\] hobbit:~$ (( hash[\$key]++ )); declare -p hash declare -A hash=(["\$key"]="1" ) hobbit:~$ let "hash[\$key]++"; declare -p hash declare -A hash=(["\$key"]="1" ["']"]="1" ) This example has come up a few times in the past. The behavior changed in bash 5.2, and it looks like 5.3 is the same as 5.2 here. This is the bash 4.0 through 5.1 result: hobbit:~$ bash-5.1 hobbit:~$ declare -A hash; key=\'\] hobbit:~$ (( hash[\$key]++ )); declare -p hash declare -A hash=(["']"]="1" ) hobbit:~$ let "hash[\$key]++"; declare -p hash declare -A hash=(["']"]="2" )