On Thu, Apr 07, 2016 at 09:38:43AM +1000, Cameron Simpson wrote: > > if $1 is set use that, otherwise use "$@" (all arguments, individually > > quoted) > > No, it says ``if $1 is set, use "$@", otherwise use nothing''. See below.
I see. So I had it exactly backwards. :) > >It seems as though this always evaluates to $1 (since if $1 is unset, > >$@ is also necessarily empty)... which I think is not what is needed > >here. Am I mistaken? I believe just "$@" (including the quotes) is > >what you want here. > > Alas, no. And also no. > > Firstly, "$@" _is_ portable; it has been around as a very special > case for decades, since at least V7 UNIX. For sure. It was the ${keword+expression} syntax I was referring to. I didn't remember coming across this syntax until I started using HP-UX 10.0 with "the POSIX shell" so I assumed it was not portable, but it seems that it is. Then again, maybe I did know that once--my memory chips have become increasingly faulty with age. ;-) > For historic reasons, "$@" evaluates to a single "" if there were no > arguments at all, introducing a spurious new empty argument. Hmmm... This is news to me, and my quick test does not bear it out: $ cat foo.sh #!/bin/sh echo "$# command line args" $ ./foo.sh "$@" 0 command line args $ ./foo.sh "" 1 command line args -=-=-=- $ cat foo.c #include <stdio.h> int main(int argc, char **argv) { printf("got %d command line args\n", argc - 1); return 0; } $ ./foo got 0 command line args $ ./foo "$@" got 0 command line args $ ./foo "" got 1 command line args In any event, it appears that your paranoid version at the least does no harm. :) -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 -=-=-=-=- This message is posted from an invalid address. Replying to it will result in undeliverable mail due to spam prevention. Sorry for the inconvenience.
pgpx1e6Z9N1Af.pgp
Description: PGP signature