Re: "${x-"$@"}" expansion

2016-05-01 Thread Chet Ramey
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 i

Re: "${x-"$@"}" expansion

2016-04-27 Thread Greg Wooledge
On Wed, Apr 27, 2016 at 07:33:25AM -0400, Grisha Levit wrote: > Sorry that wasn???t very clear. I only included that case to demonstrate that > seemingly contradictory things are happening: > >- "${_+$@}" expands each positional parameter to a separate word, >following the usual "$@" behav

Re: "${x-"$@"}" expansion

2016-04-27 Thread Grisha Levit
Sorry that wasn’t very clear. I only included that case to demonstrate that seemingly contradictory things are happening: - "${_+$@}" expands each positional parameter to a separate word, following the usual "$@" behavior - The usual "$@" behavior is to expand to 0 words if there are no

Re: "${x-"$@"}" expansion

2016-04-27 Thread Piotr Grzybowski
On 26 Apr 2016, at 21:03, 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 exp

Re: "${x-"$@"}" expansion

2016-04-26 Thread Grisha Levit
The same is true for + expansion: Multiple words: $ set -- 1 2; v=( "${#+$@}" ); declare -p v declare -a v=([0]="1" [1]="2") Empty string: $ set --; v=( "${#+$@}" ); declare -p v declare -a v=([0]="") Nothing: $ set --; v=( "${#+${#+$@}}" ); declare -p v declare -a v=()

"${x-"$@"}" expansion

2016-04-26 Thread Grisha Levit
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