[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/1.4.2.3i |
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
subshell.
> 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.
- Re: Severe Bash Bug with Arrays, (continued)
- Re: Severe Bash Bug with Arrays, Roman Rakus, 2012/04/25
- Re: Severe Bash Bug with Arrays, Greg Wooledge, 2012/04/25
- Re: Severe Bash Bug with Arrays, Greg Wooledge, 2012/04/25
- Re: Severe Bash Bug with Arrays, Chet Ramey, 2012/04/25
- Re: Severe Bash Bug with Arrays, Greg Wooledge, 2012/04/25
- Re: Severe Bash Bug with Arrays, Chet Ramey, 2012/04/25
- Re: Severe Bash Bug with Arrays, Greg Wooledge, 2012/04/25
- Re: Severe Bash Bug with Arrays, Chet Ramey, 2012/04/25
- Re: Severe Bash Bug with Arrays, Greg Wooledge, 2012/04/25
Re: Severe Bash Bug with Arrays, Ted Okuzumi, 2012/04/25
Re: Severe Bash Bug with Arrays, Linda Walsh, 2012/04/25
- Re: Severe Bash Bug with Arrays, Maarten Billemont, 2012/04/26
- Re: Severe Bash Bug with Arrays, Linda Walsh, 2012/04/26
- Re: Severe Bash Bug with Arrays, Mike Frysinger, 2012/04/27
- Re: Severe Bash Bug with Arrays, Greg Wooledge, 2012/04/27
- Re: Severe Bash Bug with Arrays, Linda Walsh, 2012/04/27