bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Grisha Levit
Subject: Re: "${x-"$@"}" expansion
Date: Wed, 27 Apr 2016 07:33:25 -0400

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 positional params but in this case "${_+$@}" expands to an empty string instead
  • If we interpret "${_+$@}" as being equivalent to "${_+}" when there are no params, then the two cases above seem reconcilable, but still "${_+${_+$@}}" expanding to nothing does not make sense.

I suspect the below is not really the desired behavior?

fun() { echo $#; }

fun "$@"
0
fun "${_+$@}"
1
fun "${_+${_+$@}}"
0
fun "${_+${_+${_+$@}}}"
1
fun "${_+${_+${_+${_+$@}}}}"
0
fun "${_+${_+${_+${_+${_+$@}}}}}"
1

FWIW bash 4.1 and below treat all but the first case as one word.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]