Reading a variable line by line with while loop
Alan McKay
alan.mckay at gmail.com
Tue Dec 1 21:51:08 UTC 2009
> echo "$Variable" | while read
> ...
> done
>
> has better chances of working.
This method has gotchas though, and I try to avoid it. The pipe
causes the while to execute in a sub shell and so any variable changes
you make inside the loop will be lost when you get out of the loop.
For this reason I often actually create a file and do the redirect as
per the original post
e.g.
while stuff
do
done < file
--
“Don't eat anything you've ever seen advertised on TV”
- Michael Pollan, author of "In Defense of Food"
More information about the ubuntu-users
mailing list