Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This Bash guide says:

If the index number is @ or *, all members of an array are referenced.

When I do this:

LIST=(1 2 3)
for i in "${LIST[@]}"; do
  echo "example.$i "

Gives: example.1 example.2 example.3 (desired result).

But when I use ${LIST[*]}, I get example.1 2 3 instead.


Edit: when using printf, @ and * actually do give the same results.

share|improve this question
It seems to work for me. I tried both @ and * and it seems to produce the same result both the times. What shell you are using? Run echo $SHELL and paste the output to your question. – Ramesh Jun 7 '14 at 14:26
My example was wrong, this actually happens only with echo, not with printf, I just noticed. – arjan Jun 7 '14 at 14:36
possible duplicate of What is the difference between $* and $@? – goldilocks Jun 7 '14 at 17:13
@goldilocks The other question is about $* 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 7 '14 at 19:31
up vote 5 down vote accepted

The difference is subtle; "$*" creates one argument, while "$@" will expand into separate arguments, so:

LIST=(1 2 3)
for i in "${LIST[@]}"; do
 echo "example.$i"

will deal with the list (print it) as multiple variables


LIST=(1 2 3)
for i in "${LIST[*]}"; do
 echo "example.$i"

will deal with the list as one variable.

share|improve this answer
I provided the wrong example, I just noticed it happens only with echo, not with printf. – arjan Jun 7 '14 at 14:38
@arjan ,see updates – Networker Jun 7 '14 at 14:39
Do you know where the difference between echo and printf comes from? Because with printf in the for loop, the * list reference is treated as multiple variables. – arjan Jun 7 '14 at 14:45
good to know, thanks @arjan – Networker Jun 7 '14 at 14:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.