BASH $* and $@

| | Comments (0)

"$*" != "$@"
* 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

Leave a comment

March 2009

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

About this Entry

This page contains a single entry by Pank published on January 12, 2006 11:07 AM.

Checksum utilities was the previous entry in this blog.

Kaspersky Anti-Hacker is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.