Adam Sznajder Adam Sznajder - 7 months ago 11
Bash Question

What's the difference between $@ and $*?

What's the difference between

$@
and
$*
? Why they have the same value but
"$@"
and
"$*"
are different when I set
IFS
to
|
?

Answer

The difference between $@ and $*: Unquoted (don't do this!), none at all: both equal $1 $2 .... With double quotes, $@ expands each element as an argument: $1 $2 ..., while $* expands to all elements merged into one argument: $1c$2c... (where c is the first character of IFS). You almost always want $@. The same goes for arrays: ${myarray[@]}

Comments