The code you provided will give the same result. To understand it better, try this:
foo () {
for i in "$*"; do
echo "$i"
done
}
bar () {
for i in "$@"; do
echo "$i"
done
}
The output should now be different. Here's what I get:
$ foo() 1 2 3 4
1 2 3 4
$ bar() 1 2 3 4
1
2
3
4
This worked for me on bash
. As far as I know, ksh should not differ much. Essentially, quoting $*
will treat everything as one word, and quoting $@
will treat the list as separate words, as can be seen in the example above.
As an example of using the IFS
variable with $*
, consider this
fooifs () {
IFS="c"
for i in "$*"; do
echo "$i"
done
unset IFS # reset to the original value
}
I get this as a result:
$ fooifs 1 2 3 4
1c2c3c4
Also, I've just confirmed it works the same in ksh
. Both bash
and ksh
tested here were under OSX but I can't see how that would matter much.