Skip to main content
1 of 2
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Using [*] will create a single string, with each element of your array delimited by the first character of $IFS (a space by default).

Using [@] will create a list.

Examples:

Creating an array:

$ list=( a b "big fish" c d ) 

Printing each element individually:

$ printf 'data: ---%s---\n' "${list[@]}" data: ---a--- data: ---b--- data: ---big fish--- data: ---c--- data: ---d--- 

Creating a single string and printing that:

$ printf 'data: ---%s---\n' "${list[*]}" data: ---a b big fish c d--- 

Again, but with a custom delimiter:

$ IFS='/' $ printf 'data: ---%s---\n' "${list[*]}" data: ---a/b/big fish/c/d--- 

Note that using these expansions without double quotes rarely makes sense.

Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k