Friday, September 16, 2005

command line arguments

"$@" produces the list of positional paramters (command line arguments).

$@ and $* are similar, but behave differently in some cases:

echo 'for word in "$@"; do echo "<$word>"; done' > /tmp/trash
sh /tmp/trash "A couple of sins" "A spaced sentence" some single


<A couple of sins>
<A spaced sentence>

but if you replace "$@" with "$*" you get

<A couple of sins A spaced sentence some single words>

and if you drop the quotation marks, as in "for words in $*; do..."


Without the quotation marks it does not matter if you use $* or $@.


Post a Comment

<< Home