BASH question

Brandon Sandrowicz bsandrow-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Dec 18 12:11:59 UTC 2007


On 12/17/07, William Park <opengeometry-FFYn/CNdgSA at public.gmane.org> wrote:
> On Mon, Dec 17, 2007 at 01:54:21PM -0500, Brandon Sandrowicz wrote:
> > ...
> > Why have him creating two scripts just to pipe one to the other?
> >
> > command | while read LINE
> > do
> >    do something w/ $LINE
> > done
> >
> > The only problem that I've had is that when setting array values
> > inside of the array, they remain local to the loop for some reason...
> > even when you declare the array outside of the loop.
>
> That's because commands in a pipe are executed in subshells (ie.
> separate processes).  So, any change to childs' environments will not
> propagate up to the parent.
>
> --
> William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
> BashDiff: Super Bash shell
> http://freshmeat.net/projects/bashdiff/

That just seems odd that you would have to output to a file, then read
that file to STDIN just ot get it to work.  I thought that was the
point of pipes, so that you *didn't* have to do that.  On the other
hand, it makes sense that commands in a pipe are executed in subshells
too.  I guess it's just a design decision. :-\

What would be the proper way to use the pipe?  Use `export` on the
array?  Or is it just impossible to use piped commands to build an
array in shell scripting?

--
Brandon Sandrowicz
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list