It is currently Sun, 19 May 2013 19:05:55 GMT



 
Author Message
 "for" and line by line
Hi,

I want to write a "for"-loop in bash such like this one:

for LINE in `cat /etc/passwd`; do
   echo $LINE
done

But I get every word, and not every line. and if I set "IFS=^M" like this:

IFS=[CTRL V][ENTER] for LINE in `cat /etc/passwd`; do
   echo $LINE
done

the bash can't read the command.

How can I realise it?

Thanks in advance

Markus Wenke



 Tue, 17 Apr 2007 15:27:13 GMT   
 "for" and line by line

On 2004-10-29, Markus Wenke wrote:

while IFS= read -r LINE
do
   echo $LINE
done < /etc/passwd

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Tue, 17 Apr 2007 15:34:21 GMT   
 "for" and line by line

See question 16 in the FAQ: http://home.comcast.net/~j.p.h/cus-faq.html#P

        Ed.



 Tue, 17 Apr 2007 20:26:47 GMT   
 "for" and line by line

In ksh and bash you can use the "escape sequence" processor $'' to
interpret escape sequences.  For example to set the IFS variable to a
"space-tab-newline":

IFS=$' \t\n'

So to set IFS to a single newline: IFS=$'\n'

All the normal escape sequences can be used inside the escape sequence
processor including hex and octal values.  See the ksh manual for more
info.

--
Dana French                            dfre...@mtxia.com
Mt Xia Technical Consulting Group   http://www.mtxia.com
100% Spam Free Email              http://www.ridmail.com
MicroEmacs                      http://uemacs.tripod.com
Korn Shell Web     http://dfrench.tripod.com/kshweb.html



 Tue, 17 Apr 2007 21:39:26 GMT   
 
   [ 4 post ] 

Similar Threads

1. man man shows "lines ?-?/?"

2. Linux "cat" and serial lines

3. "Status:" line in mail

4. Serial line "looped back"?

5. command line utility, "free"

6. pppd error: "serial line looped back"

7. "Serial line is looped back"

8. "Serial line is looped back" problem

9. pppd "Serial line looped back"

10. "help" line keeps dropping


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software