On Thu, Jan 25, 2018 at 02:48:47PM +0100, Tomasz Warniełło wrote: > Repeat-By: > 1. > $ unset A; a=" ";declare -A A; ((A[$a]++)); declare -p A > declare -A A > > 2. > $ unset A; a=" ";declare -A A; let "A[$a]=1"; declare -p A > declare -A A > > 3. > $ unset A; a=" ";declare -A A; A[$a]=1; declare -p A > declare -A A=([" "]="1" )
The first two are using a math context. If you want the $a to survive intact in this context, to make it to the array, you need some single quotes. wooledg:~$ unset A; a=" ";declare -A A; (('A[$a]++')); declare -p A declare -A A=([" "]="1" ) wooledg:~$ unset A; a=" ";declare -A A; let 'A[$a]=1'; declare -p A declare -A A=([" "]="1" ) Otherwise, the parser gets all confused. I'll let someone else attempt a more technical explanation. The third example was not using a math context; it was just a simple assignment statement. That gets parsed entirely differently.