David --
...and then David Champion said...
% On 2001.09.16, in <[EMAIL PROTECTED]>,
% "David T-G" <[EMAIL PROTECTED]> wrote:
% >
% > % Quoting FreeBSD's "man sh" [from the listing of special parameters]:
...
% > Aha! I don't use BSD (yet), so I don't have access to that, or at least
...
% > whatever it is, and Solaris doesn't mention it at all.
%
% Solaris does, just differently. The section on ${parameter} says first
% that if the parameter is "*" or "@", all positional parameters are
Hmmm -- as though $@ and $* are equivalent...
% substituted. Later, in the section on quoting, it says that if "$@"
% is encased in double-quotes, then the pos'nal params are quoted, and
% separated by unquoted spaces. Searching the manual for "@" shows this.
It sure should. I wonder how I missed it.
%
% > % first time how ${1+"$@"} works. Ingenious approach, even if a bit
% >
% > I see that "$@" protects argument expansion; what does the 1 mean? And I
% > don't have a Solaris box handy to look in a man page to reference what +
% > means; I only use :- on a regular basis.
%
% >From Solaris's sh(1):
% ${parameter:+word}
% If parameter is set and is non-null, substitute word;
% otherwise substitute nothing.
% ...
% If the colon (:) is omitted from the above expressions, the
% shell only checks whether parameter is set or not.
%
% ":+" is the flipside of ":-" -- ":-" substitutes if parameter doesn't
% have a non-null value, but ":+" substitutes if it does.
Ah, that makes sense. Of course, I dunno when I'd otherwise want to
substitute if the variable is set and not when it's not, but maybe that's
simply why it's there :-)
%
% So ${1+"$@"} means to substitute all args, quoted, if there is a first
% argument (null or not). It's equivalent to "$@" alone on most systems
% I've seen. ${1:+"$@"} is not equivalent.
I get that, but it seems as though, since the colon is omitted, it should
really do nothing, no?
%
%
% > % redundant. Most probably in the context of the tip you found it in it
% > % was a workaround for a shell that didn't handle a plain "$@" correctly?)
%
% It's possible that some shells might issue an error evaluating "$@" if
% no arguments are present. csh(1) does this by design when evaluating
% any variable. This is the kind of behavior I wouldn't be surprised to
Right...
% see in older versions of AIX, for example; it's sometimes been fairly
% strict in its response to undefined conditions. Most systems substitute
% nothing if there are no args. UNIX98 requires this, but I can't say with
That makes sense and is what I'd expect from a shell that can handle $VAR
being empty (like csh cannot except for the $?VAR test).
% certainty that prior versions of this standards family require anything
% particular, so ${1+"$@"} might well be needed for backward compatibility
% to POSIX or XPG or something. I don't know where to find these standards
% online; the Open Group no longer offer previous editions to SUS.
Ah, well.
%
% --
% -D. [EMAIL PROTECTED] NSIT University of Chicago
Thanks for the very informative reply!
:-D
--
David T-G * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
PGP signature