$@ vs. $* (was - Re: nohup (from Bourne shell))

karl at haddock.UUCP karl at haddock.UUCP
Sat Dec 13 11:59:50 AEST 1986


In article <164 at its63b.ed.ac.uk> simon at its63b.ed.ac.uk (ECSC68 S Brown CS) writes:
>In article <106 at quacky.UUCP> dce at quacky.UUCP (David Elliott) writes:
>>Anyway, the following statement can be used to fix [the $@ bug] ...
>
>However, if you fix this in your version of sh, it makes any shell-scripts
>that you may write assuming the "fixed" behaviour inherently non-portable,
>'cos they'll immediately bomb out on standard shells.

Shell scripts are already non-portable across versions of UNIX.  The three
major branches (Research, USG, and Berkeley) have distinct versions of echo!
Hopefully the $@ fix will be applied to an entire branch rather than being
done individually at each installation.  (I presume nobody *depends* on this
bug...)  Research V8 has already applied the fix, I believe.

>So, until [it] is official, its probably better just to be very careful...
>One foolproof way is to always use ${1+"$@"} in place of $* or $@ or "$@"...

Hey!  That's not bad!  I've been using crap like
	if [ $# = 0 ]; then cmd; else cmd "$@"; fi
which is uglier -- if your notation really works (it should, but I'm going to
run some tests before I rewrite things) I'll convert my shell scripts.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
Btw, the V8 echo is the best of the lot; I hope the others adopt it.



More information about the Comp.unix.questions mailing list