Subject: Re: appending to a shell variable inside a loop
To: None <cube@cubidou.net>
From: None <brook@biology.nmsu.edu>
List: netbsd-help
Date: 03/11/2004 09:15:38
Thanks for the quick response.
cube@cubidou.net writes:
> Using a pipe here means you're launching the while loop in a sub-shell.
> Hence, $LIST inside the loop is not the same as the external $LIST, and
> get lost when the sub-shell exits.
I knew it was something obvious that I wasn't seeing.
> The 'cat -' here is really useless, just remove it and 'read' will take
> its input from the standard input anyway.
In "real life" I'm not use cat. The loop is the end of a pipeline,
though, so cat served that purpose here.
> If you really need a cat here, you'll have to make the sub-shell return
> a value on the standard output, and assign it, or something like that.
So LIST=$(<contents of pipeline with loop>) works fine.
Thanks.
Cheers,
Brook