Re: "for" and line by line

dfrench_at_mtxia.com
Date: 10/29/04


Date: 29 Oct 2004 06:39:26 -0700


Markus Wenke wrote:
> 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.
>

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                            dfrench@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


Relevant Pages