Adam Sznajder
Adam Sznajder

Reputation: 9216

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 |?

Upvotes: 1

Views: 224

Answers (1)

Gilles Quénot
Gilles Quénot

Reputation: 185760

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[@]}

Upvotes: 5

Related Questions