bug-bash
[Top][All Lists]
Advanced

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

Re: "$@" vs. nounset


From: Chet Ramey
Subject: Re: "$@" vs. nounset
Date: Mon, 29 Jun 2009 16:53:44 -0400
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)

Mike Frysinger wrote:
> On Monday 29 June 2009 04:54:52 Yang Zhang wrote:
>> Hi, I like using nounset for stricter scripts, but an annoyance is that
>> anytime I use "$@" and it's empty, I get an error, when (to me,
>> cognitively) it is not "unset" (as in someone *forgot* to set it), it's
>> just an empty, which is a common case (IIRC, in bash, variables set to
>> empty arrays and unset variables are the same).
>>
>> As a result I'm forced to use "${@:-}" or something like that everywhere
>> I use "$@" (which is really everywhere).  Is there any other way around
>> this?  Any way to get a more selective nounset?  Thanks in advance.
> 
> if you search the archives, i think the previous discussion on this topic 
> said 
> bash-4's behavior needed to change here

It's not quite that simple.  And the discussion you reference took place
on the austin-group list, not bug-bash.

First of all, the bash-3.x behavior was inconsistent.  $@ did not exit
the shell, but address@hidden did.

When I got bug reports about the behavior, I took a look around.  Posix.2
said that set -u applied only to "variables", which have a specific
definition and do not include $@, $* or any other special parameter.  This
was so far from existing practice, I figured that it was another case of
the set -e issue: Posix.2 wanted to standardize existing practice, but
messed up.  So I changed bash-4.0 to match existing shell practice, and
asked for an interpretation.

The interpretation process went back and forth, and we finally decided
that set -u will apply to references to every variable, parameter, and
special parameter *except* $@ and $*.  That's going to be in the next
revision of the standard.

In the meantime, I have a patch in the pipeline that will implement the
behavior described in the Posix interpretation.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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