On 4/25/12 1:23 AM, Clark Wang wrote:
>> Bash Version: 4.2
>> Patch Level: 0
>> Release Status: release
>>
>> Description:
>> Cannot redirect into an array from multiline variable
>>
>> Does not work:
>> echo "$mydata" | while read line; do myarray+=( "$line" ); done
>>
>
> Here the whole *while* statement runs in a subshell. See
> http://mywiki.wooledge.org/BashPitfalls#grep_foo_bar_.7C_while_read_-r.3B_do_.28.28count.2B-.2B-.29.29.3B_done.
Since you're using bash-4.2, you can experiment with the `lastpipe' shopt
option. If that's enabled, bash runs the last element of a pipeline in
the parent shell context without creating a subshell.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/