On 4/26/16 3:03 PM, Grisha Levit wrote: > This behavior seems very strange. This example is with $@ but it seems the > same for ${array[@]} > > The manual says for ${parameter:-word}: > >> If parameter is unset or null, the expansion of word is substituted. > > In this case, $@ is expanded as if it was quoted (even if 'word' is not > quoted) and the outer quotes do no serve to quote the expansion of $@. > > $ set -- '1 1' '2 2'; unset x > $ v=( "${x-$@}" ); declare -p v > declare -a v=([0]="1 1" [1]="2 2") > > In this case though, the expansion is an empty string rather than nothing > so it seems that a different set of rules is being followed:
Thanks for the report. This was discussed by the austin group back in 2014 and resulted in Posix interpretation 888. > > $ set -- > $ v=("$@"); declare -p v # obviously > declare -a v=() > $ v=( "${@-$@}" ); declare -p v # ? > declare -a v=([0]="") > > The following is strange, in light of the above: > > $ v=("${@-${@-$@}}"); declare -p v > declare -a v=() It took longer to track down and fix this than any of the nameref issues. This will be fixed in bash-4.4. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/