[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Severe Bash Bug with Arrays

From: Greg Wooledge
Subject: Re: Severe Bash Bug with Arrays
Date: Wed, 25 Apr 2012 13:43:54 -0400
User-agent: Mutt/

On Wed, Apr 25, 2012 at 10:36:53AM -0700, Ted Okuzumi wrote:
> Please note that if I use a different command in the while loop it works.
> So instead of
> echo "$mydata" | while read -r line; do myarray+=( "$line" ); done
> if I say:
> echo "$mydata" | while read -r line; do echo "$line" ; done

You do not appear to understand the issue here.  Each command in a pipeline
is run in a separate subshell.  That means "echo" runs in its own subshell,
and the entire "while" loop runs in its own subshell.

In the first example, you are populating a variable inside this subshell.

After the pipeline ends, that subshell is gone, and so is the variable
that you populated.

In the second example, you are simply writing things to stdout.  You are
not populating variables that need to persist beyond the lifespan of the

> Then it works.  To pipe output into a while statement works, normally,
> however it fails when the array+=( )  is used.  It doesn't fail on other
> commands that I've seen.
> This is why I am saying it is definitely a bug.  Do you not agree?

I do not agree.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]