Consider the simple case that list elements do not contain special characters (e.g. blanks). Then the quotes can be dropped. Then @ and * will give the same result.
LIST=(1 2 3)
for i in ${LIST[*]}; do
echo "example.$i"
done
ouput:
example.1
example.2
example.3
Now consider the case that elements contain blanks:
LIST=(1 "a b" 3)
for i in ${LIST[*]}; do
echo "example.$i"
done
In this case, @ and * still give the same result:
example.1
example.a
example.b
example.3
But it is not what we desire since "a b" is split as two elements rather than one elmement. So we need to use quotes to prevent this:
LIST=(1 "a b" 3)
for i in "${LIST[*]}"; do
echo "example.$i"
done
But the result is example.1 a b 3
. Next we change * to @:
LIST=(1 "a b" 3)
for i in "${LIST[@]}"; do
echo "example.$i"
done
We finally get the desired result:
example.1
example.a b
example.3
Summarizing the above result, we see that @ allows element-wisely operation when being operated by some operators, e.g. quote marks.
echo $SHELL
and paste the output to your question. – Ramesh Jun 07 '14 at 14:26echo
, not withprintf
, I just noticed. – arjan Jun 07 '14 at 14:36$*
and$@
. Though, the answer would be similar and one question could be considered a subset of the other, they are different questions. – Stéphane Chazelas Jun 07 '14 at 19:31