Comment 3 for bug 1618224

Revision history for this message
xhienne (xhienne) wrote :

Not a bug IMHO, but that may be open to debate. At least the observed behavior conforms to the bash manual which reads:
- ((expression)) is strictly equivalent to: let "expression"
- parameter expansion is performed _before_ the expression is evaluated

Therefore, ((++a[$b])) translates to let "++a[$b]" which translates to let "++a[80's]" which leads to an error.

The proper syntax would be (('++a[$b]')) which is admittedly quite counter-intuitive. This way '$b' is evaluated as a whole during the arithmetic evaluation.

Demonstration:
$ declare -A a
$ b="80's"
$ (('++a[$b]'))
$ printf '%s\n' "${!a[@]}" "${a[@]}"
80's
1
$ (('++a[$b]'))
$ printf '%s\n' "${!a[@]}" "${a[@]}"
80's
2