Interview Prep/Shell Scripting/Arrays, conditionals and loops

What is the difference between `"${arr[@]}"` and `"${arr[*]}"`?

IntermediateConceptArrays, conditionals and loops
Answer

"${arr[@]}" expands to one word per element, preserving spaces. "${arr[*]}" joins all elements into a single word separated by the first character of IFS.

files=("a b.txt" c.txt)
ls -l "${files[@]}"                  # two arguments
(IFS=,; echo "${files[*]}")          # a b.txt,c.txt  (join in a subshell)

Use [@] to pass elements to commands and [*] to build a display string.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops