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>
.



Relevant Pages

  • Re: bash/sh shell scripts and line-based list expansion
    ... is there a way in bash/sh to get for loops to iterate a single line at a ... rather than a single word? ... stuff with word1 ... ...
    (comp.os.linux.setup)
  • RE: Refer to Column with a variable
    ... The A1 notation does not seem to be conducive to this, ... I'm creating a macro that will create a data sheet for me. ... I have loops that iterate through the columns and rows to set up my ...
    (microsoft.public.excel.programming)
  • Re: [PATCH 2/2] page table iterators
    ... we basically have that bunch of loops that all do the same thing ... to iterate the page tables. ... and 3 level page tables easily, regaining some of the perfs lost by the ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Optimisation for tight loops...
    ... knowing better perl is the way to write better loops, ... my $searchfor = 99999; ... my $code_Perl_grep = sub { ...
    (comp.lang.perl.misc)
  • Re: how do prlglobs expand (was Re: nobody using sudo -- scary!)
    ... What would happen if I use follwing statement in perl" ... iterate through them. ... in the case of foreach. ... For example, if I put a "last" in the while loop, the code still performed ...
    (comp.lang.perl.misc)