Skip to main content

The difference is subtle; "${LIST[*]}" (like "$*") creates one argument, while "${LIST[*]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,.

butBut:

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

will deal with the list as one variable.

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.

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.

improve phrasing, note that the behaviour is similar between array indexing and the special parameters * and @
Source Link
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.

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"
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.

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.

Minor change to formatting
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

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"
done
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
LIST=(1 2 3)
for i in "${LIST[*]}"; do
 echo "example.$i"
done

will deal with the list as one variable.

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"
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.

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"
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.

deleted 4 characters in body
Source Link
Nidal
  • 9.1k
  • 11
  • 59
  • 74
Loading
Source Link
Nidal
  • 9.1k
  • 11
  • 59
  • 74
Loading