Description of problem: Different undocumented behaviour change Version-Release number of selected component (if applicable): bash-4.3.18-2 How reproducible: Always Steps to Reproduce: Affected example command: bash -x -c 'arr[0]=; arr[1]=; [[ ${arr[@]} ]] || echo false' 1. Run the command on Fedora 21 with bash-4.3.18-2 2. Run the same commmand in Fedora 20 or Ubuntu (bash 4.3.11) Results: Result is "true", which is not as expected as the same command returns "fals" from RHEL 5 to Fedora 20. Additional info: Couldn't find any documentation or changelog regarding this change. This breaks a lot of scripts. Also setting BASH_COMPAT to 4.2 does not revert to the original behaviour. Fedora 20 output: $ bash -x -c 'arr[0]=; arr[1]=; [[ ${arr[@]} ]] || echo false' + arr[0]= + arr[1]= + [[ -n '' ]] + echo false false Fedora rawhide output: $ bash -x -c 'arr[0]=; arr[1]=; [[ ${arr[@]} ]] || echo false' + arr[0]= + arr[1]= + [[ -n ]]
This is introduced here: http://git.savannah.gnu.org/cgit/bash.git/commit/?id=3b34f6e68ce94b15608a49feb62702a71bc18665
Michael is right, this was buggy behaviour fixed by patchlevel 14. To explain: According to man pages, ${arr[@]} expands the array into separate words (analogous to the expansion of $@). Quoting the man page: 'That is, "$@" is equivalent to "$1" "$2" ...' So what it basically becomes in your example is <value-of-arr0><separator><value-of-arr1>. Substituting the relevant piece of code with [[ \"${arr[@]}\\" ]] demonstrates this well. There are minor distinctions in expanding using * and @. The man page states: "If the word is double-quoted, ${name[*]} expands to a single word with the value of each array member separated by the first character of the IFS special variable". Meaning, the correct way to write your example line and get the behaviour you want is: bash -x -c 'IFS=; arr[0]=; arr[1]=; [[ "${arr[*]}" ]] || echo false'
Correction: Substituting the relevant piece of code with [[ \"${arr[@]}\" ]] demonstrates this well.
Thanks for the explanation. This is really big, we probably need to audit all the code as this has been built on foundations like this since 2000'.
No problem. And yes, it's actually the most common use, that's always been the undocumented one :/ .