Esta pergunta é semelhante a esta , mas difere dela:
Considere esta matriz com elementos de string que podem conter espaços:
a@W:$ arr=("eins" "zwei" "eins plus zwei" "vier" "fünf")
a@W:$ echo ${#arr[@]} # ok, 5 elements, as expected
5
a@W:$ echo ${arr[3]} # the fourth one, indexing starts at 0
vier
a@W:$ echo ${arr[2]} # the third one, which contains two blancs
eins plus zwei
a@W:$ ar2=${arr[@]:0:3} # I only want the firs three of them
a@W:$ echo ${ar2[@]}
eins zwei eins plus zwei
a@W:$ echo ${#ar2[@]} # but they are all glued together into one element
1
a@W:$
O que devo fazer para evitar que isso os cole todos juntos? A string contendo espaços, "eins plus zwei" deve permanecer o terceiro elemento.