> tst1 a b "c d" > > tst2 $* <-- this would expand above to 4 args instead of 3. > tst2 "$*" <-- this would expand above to 1 arg instead of 3. > > How do I get the original three args?
tst2 "$@"
is equivalent to using
tst2 "$1" "$2" "$3"
In summary, for original example:
$@ 4 args $* 4 args "$*" 1 arg "$@" 3 args!
Beside, when there are no positional parameters, “$@” and $@ expand to nothing (i.e., they are removed). No need to play the trick ${1+"$@"}!
That "$@" string is sort of magical in the Bourne shell, it makes all the strings come out properly quoted. Not doubt there is some way to accomplish the same thing in csh/tcsh, but I don't know offhand how. Do yourself a favor and use tcsh as your interactive shell if you like, but program in sh/ksh.
documented on: 2000.06.21 Wed 16:30:54