Re: bash/sh shell scripts and line-based list expansion



On Wed, 24 Jan 2007 14:02:09 -0600, Jules
<julesrichardsonuk@xxxxxxxxxxxxxxxxxxxxxxx> wrote:



[sorry - there's probably a better linux group to ask this in]

is there a way in bash/sh to get for loops to iterate a single line at a
time, rather than a single word?

In other words, given something like:

for i in `cat /tmp/foo`; do echo ${i}; done

...the default behaviour is for the variable i to be set to each "word"
(i.e. something separated by whitespace) from the file /tmp/foo for
each loop iteration.

What I need is for the i variable to be set to each line in turn.

IFS= ; while read -r i; do echo $i; done < /tmp/foo


--
To Perl, or not to Perl, that is the kvetching.
-- Larry Wall in <199801200310.TAA11670@xxxxxxxx>
.