Quantcast
Channel: Print array elements on separate lines in Bash? - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Gilles Quénot for Print array elements on separate lines in Bash?

$
0
0

Try doing this :

$ printf '%s\n'"${my_array[@]}"

The difference between $@ and $*:

  • Unquoted, the results are unspecified. In Bash, both expand to separate argsand then wordsplit and globbed.

  • Quoted, "$@" expands each element as a separate argument, while "$*"expands to the args merged into one argument: "$1c$2c..." (where c isthe first char of IFS).

You almost always want "$@". Same goes for "${arr[@]}".

Always double quote them!


Viewing all articles
Browse latest Browse all 9

Trending Articles