On Wed, Oct 28, 2015 at 11:35:42AM +0100, Oskar Maier wrote: > http://stackoverflow.com/questions/33371309/change-in-behaviour-of-declare-local-from-bash-4-2-to-4-3
Here is the text: ============================== I've recently updated my system and got a new bash version. Since then I've encountered some nasty behaviour of my bash scripts, which I finally managed to track down to a new behaviour of bash's declare / local commands. Considering the following minimal working example: #!/bin/bash function printarray1 () { local -a arr=("${!1}") echo "${arr[@]}" # printing the complete array echo "${arr[9]}" # just to check if it is really recognized as an integer indexed array } function printarray2 () { local arr=("${!1}") echo "${arr[@]}" # printing the complete array echo "${arr[9]}" # just to check if it is really recognized as an integer indexed array } arr=("01" "02" "03" "04" "05" "06" "07" "08" "09" "10") echo "Declaration as indexed array:" printarray1 arr[@] echo "Undefined declaration:" printarray2 arr[@] On GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) this results in Declaration as indexed array: 01 02 03 04 05 06 07 08 09 10 10 Undefined declaration: 01 02 03 04 05 06 07 08 09 10 10 while the newer GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) version returns Declaration as indexed array: Undefined declaration: 01 02 03 04 05 06 07 08 09 10 10 Note that the behaviour is the same when I use "declare" instead of "local". I could not find anything about a change of the declare options in Bash 4.3. The help (help declare) is equal in both versions for all relevant information. I've even stumbled upon the claim that "All variables can be used as arrays without explicit definition." (see Why are "declare -f" and "declare -a" needed in bash scripts?). Can anyone explain this behaviour? Is it a new feature? Or simply a bug? Has the passing of arrays to functions been restricted? To me it's pretty scary when the bash behaviour suddenly changes from version to version. ==============================