In Bourne shell and its offshoots like Bash, I believe the only difference between $*
and $@
is that $@
expands in double quotes so that each argument ends up as a single word even if it contained embedded whitespace while $*
doesn't.
#!/bin/sh
for i in $*; do echo $i; done
for i in $@; do echo $i; done
for i in "$*"; do echo $i; done
for i in "$@"; do echo $i; done
...when invoked with '1 2' 3
as arguments, the first two output 1
, 2
, then 3
, the thrid outputs 1 2 3
, but the fourth correctly outputs 1 2
then 3
.
Is $*
just redundant, and if it is, why is it used in so many scripts?