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
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1618224
Title:
Single quote character not handled well in associative array index
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1618224/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs