Hello dear bash-bug mailing-list! I am puzzled by bash behavior with array assignments.
It seems there is a behavior change introduced in bash 4.3 in array assignments. An array can actually reference itself in its own declaration. $ declare -A foo=([bar]=1st) ; foo=([bar]=2nd [qwer]=${foo[bar]}) ; echo "${foo[@]}" 2nd 2nd $ bash --version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) $ declare -A foo=([bar]=1st) ; foo=([bar]=2nd [qwer]=${foo[bar]}) ; echo "${foo[@]}" 2nd 1st $ bash --version GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) Is this a bug or a feature? I would have expected the bash <= 4.2 behavior to be right on the principle you cannot define *and* use regular variables at the same time. E.g.: "declare foo=bar gee=$foo" will not assign bar to gee. Plus, regular arrays behave "normally" in both bash 4.2 and 4.3: $ declare -a foo=(1st) ; foo=(2nd ${foo[0]}) ; echo ${foo[@]} 2nd 1st $ bash --version GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) $ declare -a foo=(1st) ; foo=(2nd ${foo[0]}) ; echo ${foo[@]} 2nd 1st $ bash --version GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) Another weirdness (I think) is this: $ declare -A foo=([bar]=asdf [baz]=qwer) ; foo+=([bar]=asdf [baz]=qwer) ; echo "${!foo[@]}" "${foo[@]}" bar baz asdfasdf qwerqwer Man page says : When += is applied to an array variable using compound assignment (see Arrays below), the variable's value is not unset (as it is when using =), and new values are appended to the array beginning at one greater than the array's maximum index (for indexed arrays) or added as additional key-value pairs in an associative array. There's nothing about appending content to already-existing values. Honestly, I would expect the key/value to be replaced, but that could just be my mind being too twisted. Regards, D -- Damien Nadé <dnade....@orange.com> Astek Sud-Est pour Orange/OF/DSIF/DFY/SFY/DO Sophia Antipolis - France / Tel : 04 97 46 28 74 _________________________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you.