|
| From: | Paul Jarc |
| Subject: | Re: Bash forgets array values outside of a while loop |
| Date: | Tue, 20 Nov 2001 01:03:52 -0500 |
| User-agent: | Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7 (i386-redhat-linux-gnu) |
Joe User <bergeron@vallnet.com> wrote:
> ( for i in 0 1 2 3 4 ; do echo $i ; done ) |
> while read f[$fnum]; do echo "${f[@]}";
> fnum=$(($fnum+1)); done
See FAQ entry E4. Each element of a pipeline is run in its own
process. (Thus your subshell for the first element is also
redundant.)
> Almost like f has scope within the while loop.
The scope is the pipeline element. This will show the value set in
the loop:
... | { while read blah; do foo; done; echo $blah; }
paul
| [Prev in Thread] | Current Thread | [Next in Thread] |