I'm having trouble building a bash array from standard output. I threw it back to this minimal example:
~$ a=($(echo '1 2 3 "foo bar"'))
~$ echo ${a[0]}
1
~$ echo ${a[1]}
2
~$ echo ${a[2]}
3
~$ echo ${a[3]}
"foo
~$ echo ${a[4]}
bar"
I think that what happens is that "foo, and bar"are treated as separate elements of the standard output, but the aim would be to combine these elements in a single array.
Obviously, I could write a short cycle to combine these terms into one, but I wonder if there is a more elegant solution?
EDIT : what happens instead echo '1 2 3 "foo bar"'in my code is rather confusing, but the fact is that I need to form an array from the unknown standard output of this form .