On 7/9/25 4:57 PM, Robert Elz wrote:
jacaranda$ echo "$BASH_VERSION" 5.3.0(1)-release jacaranda$ unset hash jacaranda$ declare -A hash; key=\'\] jacaranda$ let "hash[\$key]++"; declare -p hash declare -A hash=(["']"]="1" )So it is still different, just different different.
`let' is a builtin, so it has a well-defined word expansion sequence. You should be able to replace it with a shell function and have the same thing happen as when you call the builtin directly. That exempts it from the internal quoting the shell can do with ((, since that's a compound command. So, since you don't have assoc_expand_once set -- what started this entire discussion back in 2021 in the first place -- the subscript is expanded twice. `let' sees "hash[$key]++", and the array expansion in the arithmetic evaluation evaluates the subscript again. You have to quote your way out of trouble. This was essentially the entire substance of the discussion in 2021 that prompted these changes.
And for this, the (( )) version is clearly correct, the '\' that is inserted before the $ in a string which is (as Chet said) treated as double quoted, prevents the '$key' from being a variable reference, and instead makes it be just the 4 characters '$' 'k' 'e' 'y' (and in which "declare -p" needs to similarly escape the '$' for correctness).
Correct. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature