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:

$ 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=()

Reply via email to