Re: "read" array variables via pipe vs. redirection
On Tue, 18 Mar 2008 07:04:36 +0100, Cyrus Kriticos wrote:
>> "${function}" | read -a var; echo ${#var[@]} ${var[*]}
>> 0
>>
>> however:
>>
>> "${function}" > file; read -a var < file; echo ${#var[@]} ${var[*]}
>> 4 566 269 732 435
>
> $ echo 566 269 732 435 | while read -a var; do echo ${#var[@]}
> ${var[*]}; done 4 566 269 732 435
Yes, that works, but I really don't wish to "do ...;done" anything at the
time, just assign the variable array. "read -a var" should, according to
the bash man page, assign the array from stdin. I don't understand the
need to echo the values during a single-pass while loop.
$ echo 566 269 732 435 | while read -a var; do cat /dev/null; done
$ echo ${#var[@]} ${var[*]}
0
|