in reply to Re: what's the difference between "$@" and ${1+"$@"}
in thread what's the difference between "$@" and ${1+"$@"}

The syntax isn't quite ${1:+$foo}, and hence "this" or "that". I've never seen any documentation of the syntax ${foo+"$bar"}.

I'm just curious what the 1+ does in this context. If there are actual arguments in "$@", the 1+ doesn't seem to modify the end result at all. So, if "$@" is empty, do we get instead the return value of the first positional parameter $1, which happens also to be empty? Or does the 1+ just act to clean up the return value of the empty "$@".

Replies are listed 'Best First'.
Re^3: what's the difference between "$@" and ${1+"$@"}
by ikegami (Patriarch) on Oct 09, 2007 at 17:05 UTC

    From the manual,

    If the colon (:) is omitted from the above expressions, the shell only checks whether parameter is set or not.

      Aha! Now it makes sense. Thanks everyone, especially Merlin, for your imparted wisdom...

      And I finally found a web page that discusses this, with some good background detail.

      http://www.in-ulm.de/~mascheck/various/bourne_args

      As an interesting side note, I wonder if anyone knows how to give this string (${1+"$@"}) to Google's search engine. As is, it doesn't work. I tried single-quoting it, and it still doesn't work.

      Cadphile...