Email List: Xaustin-group-lX
[All Lists]

Re: $@ and set -u

To: Chet Ramey <chet.ramey@xxxxxxxx>
Subject: Re: $@ and set -u
From: Stephane Chazelas <stephane_chazelas@xxxxxxxx>
Date: Thu, 30 Apr 2009 17:42:25 +0100
Cc: dgk@xxxxxxxxxxxxxxxx, austin-group-l@xxxxxxxxxxxxx
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.fr; h=Received:X-YMail-OSG:X-Yahoo-Newman-Property:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent; b=Ynfq7m0uMxJ1dra5UFM3S9EntrvvAZscCwHKsKbBIoM2NIoXFxGdhB9nFfW9dxx2UqA8bgZY1w38sqByyiXPmDBbo9RtPr8oPPacH140tq3qI8+5obum1QT7nAieLIvhVE4svyakVLSqlu1w05N8ARrRM1LmOhuZgW24tE3FUK4= ;
References: <200904301329.n3UDTOXH005366@penguin.research.att.com> <090430150616.AA84655.SM@caleb.INS.CWRU.Edu>
2009-04-30 11:06:16 -0400, Chet Ramey:
[...]
> I also tested a fairly extensive list of open source shells, and dash
> was the only one claiming Posix compliance that doesn't make it a fatal
> error.  (zsh doesn't raise an error, but I wasn't running it in sh or ksh
> mode.)
[...]

zsh in sh mode behaves like dash:

$ ARGV0=sh zsh -uc ': $*; echo ok'
ok
$ ARGV0=sh zsh -uc ': $1; echo ok'
zsh:1: 1: parameter not set

(the ARGV0 thing is zsh's way to specify the argv[0] of a
command being executed)

I agree that behavior makes more sense. I don't expect anyone to
rely on the shell being exited when expanding $@/$* while $# ==
0 and -u is set, so changing the behavior is probably safe
enough.

ksh and bash might also want to consider how to treat other
arrays (though that's out of POSIX scope).

BTW,

$ ksh -uc 'set -A a; echo ${a[@]}; echo ok'
ksh: line 1: a[(null)]: parameter not set

That sounds like a bug (that null thing).

Cheers,
Stephane

<Prev in Thread] Current Thread [Next in Thread>