Skip to main content
4 of 5
improve phrasing, note that the behaviour is similar between array indexing and the special parameters * and @
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

The difference is subtle; "${LIST[*]}" (like "$*") creates one argument, while "${LIST[*]}" (like "$@") will expand each item into separate arguments, so:

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

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

but

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

will deal with the list as one variable.

Nidal
  • 9.1k
  • 11
  • 59
  • 74