Newsgroups: comp.lang.tcl,comp.unix.shell From: bet@ritz.mordor.com (Bennett Todd) Subject: Re: "$@" versus ${1+"$@"} References: <438pn6$abm@tbird2.pad.otc.com.au> <9526104.11082@mulga.cs.mu.OZ.AU> <448lkd$cg1@ukwsv3.ggr.co.uk> Followup-To: comp.unix.shell Date: Tue, 26 Sep 1995 14:35:45 GMT Message-ID: (This isn't really a TCL question; it's a Bourne Shell question; so I've cross-posted, and set followups, to comp.unix.shell). Once upon a time (or so the story goes) there was a Bourne Shell somewhere which offered two choices for interpolating the whole command-line. The simplest was $*, which just borfed in all the args, losing any quoting that had protected internal whitespace. It also offered "$@", to protect whitespace. Now the icko bit is how "$@" was implemented. In this early shell, the two-character sequence $@ would interpolate as $1" "$2" "$3" "$4" ... $n so that when you added the surrounding quotes, it finished quoting the whole schmeer. Cute, cute, too cute.... Now consider what the correct usage "$@" will expand to _if_there_are_no_args_: "" That's the empty string --- a single argument of length zero. That's _not_ the same as no args at all. So, someone came up with a clever application of another Bourne Shell feature, conditional interpolation. The idiom ${varname+value} expands to ``value'' if ``varname'' is set, and nothing otherwise. Thus the idiom under discussion ${1+"$@"} means exactly, precisely the same as a simple "$@" without that ancient, extremely weird bug. So now the question: what shells _had_ that bug? Are there any shells shipped with any even vaguely recent OS that included it? -- -Bennett bet@mordor.com http://www.mordor.com/bet/