Shell Script : Difference between $* and $@

$*   – All command line parameters

$@  – All command line parameters

“$*” – takes the entire list as one argument

“$@” – takes the entire list and seperates into seperate arguments

bash-3.00$ less test.sh
#!/usr/bin/sh

for str in “$*”
do
echo $str
done

bash-3.00$ ./test.sh a b c
a b c

bash-3.00$ less test.sh
#!/usr/bin/sh

for str in $*
do
echo $str
done

bash-3.00$ ./test.sh a b c
a
b
c

1 Comment »

  1. math said

    Hi,
    Thanks, Very nice explanation. Easy to understand.

RSS feed for comments on this post · TrackBack URI

Leave a Comment