On 23:00 07 Nov 2002, Leonard den Ottolander <[EMAIL PROTECTED]> wrote:
| > Us raw input instead:
| >     while read -r line; do echo ${line}; done < somefile
[...]
| > you will get exactly that as output. Use "help read | less" at the
| > bash command line for more info.
| 
|  Just the switch I was looking for. Tried man read, but that doesn't state the 
| -r option. Guess I'll have to use help for bash internals. Thanks.

Or "man bash".

|  Still leaves me with the question whether I can pipe command output into a 
| while loop. I'll have a look at the for loop as well.

Sure you can pipe to loops. Just remember that the loop will be in a subshell
so any variable settings won't have effect on the main shell. Thus:

        a=1
        ls | while read -r file; do a=$file; done
        echo $a

will say "1". Usually if I need the loop to have effects on variables
I do this:

        a=1
        ls \
        | { while read -r file; do a=$file; done
            echo $a
          }
        echo $a

which will print "foo" and then "1" (if "foo" were the last listed
filename).

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

It's in the rich legal tradition of Apple Computer who, in their famous
suit against Microsoft and HP, claimed that the idea of ripping off
Xerox was their intellectual property.
        - John Iodice <[EMAIL PROTECTED]>



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to