What is the difference between $ @ and $ * in shell scripts?

advertisements

In shell scripts, what is the difference between [email protected] and $*?

Which one is the preferred way to get the script arguments?

Are there differences between the different shell interpreters about this?


From here:

[email protected] behaves like $* except that when quoted the arguments are broken up properly if there are spaces in them.

Take this script for example (taken from the linked answer):

for var in "[email protected]"
do
    echo "$var"
done

Gives this:

$ sh test.sh 1 2 '3 4'
1
2
3 4

Now change "[email protected]" to $*:

for var in $*
do
    echo "$var"
done

And you get this:

$ sh test.sh 1 2 '3 4'
1
2
3
4

(Answer found by using Google)