I'm using bash to create a script outputting a set of values (one per line), then run it, and then put the output into an array. I want to retain the empty lines as empty array elements, because an empty value is still a value and it's the only way to match up to the list of values I was expecting back.
So for the following bash code:
> IFS=$'\n'
> foo=( $(echo 'foo bar'; echo; echo; echo baz) )
> echo ${#foo[@]}
2
I expected to see 4 output, because there were four lines of output. Instead only the lines with something on them are included, so there are only two values in the array.
The following alternatives didn't help:
> foo=( `echo 'foo bar'; echo; echo; echo baz` )
> echo ${#foo[@]}
2
> foo=( "$(echo 'foo bar'; echo; echo; echo baz)" )
> echo ${#foo[@]}
1
How can this be done?
bash?