Re: What does ${1+"$@"} mean?
am 19.12.2007 04:00:52 von AZ Nomad
On Mon, 17 Dec 2007 17:10:24 -0800 (PST), lihao0129@gmail.com wrote:
>Dear shell experts:
>In Programming Perl edition-3 page 488, I saw this line:
> eval `exec perl -S $0 ${1+"$@"}`
>I know ${1+"$@"} works just like $* or the like, but I just dont know
>how the 1+"$@" thing works around? Can you shed some light to me on
>this problem..
sheesh. Which character don't you understand? :-p
Re: What does ${1+"$@"} mean?
am 19.12.2007 09:22:11 von wayne
AZ Nomad wrote:
> On Mon, 17 Dec 2007 17:10:24 -0800 (PST), lihao0129@gmail.com wrote:
>> Dear shell experts:
>
>> In Programming Perl edition-3 page 488, I saw this line:
>
>> eval `exec perl -S $0 ${1+"$@"}`
>
>> I know ${1+"$@"} works just like $* or the like, but I just dont know
>> how the 1+"$@" thing works around? Can you shed some light to me on
>> this problem..
>
> sheesh. Which character don't you understand? :-p
${var+value} means to evaluate to var IF var is not set, otherwise
evaluate to "value". So "${1+"$@"| will evaluate to $1 if there is
no parameters, resulting in nothing. If $1 is defined then this
evaluates to "$@" instead. The idea is that a few older shells
are broken and if there are no parameters set, "$@" still becomes
a zero-length parameter rather than nothing. If you use a decent
shell, just use "$@" and don't worry about it. If your script may
be used by others with older shells, it pays to play safe and
use the hack.
-Wayne