January 12, 2006

BASH $* and $@

"$*" != "$@"
* When the expansion occurs within double quotes, it expands to a single word.
@ When the expansion occurs within double quotes, each parameter expands to a separate word.
Without double quotes, $* = $@

test.sh
#!/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

# ./test.sh 1 2
1 2
1
2
1
2
1
2

ref. Bash Reference Manual - Special Parameters, Double Quotes

Posted by pank at January 12, 2006 11:07 AM
Comments
Post a comment













Remember personal info?