Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Reading line by line



On Tue, Apr 10, 2007 at 08:56:49PM -0700, Micah Cowan wrote:
> meino.cramer@xxxxxx wrote:
> > Hi,
> > 
> >  how can I read line by line from a file of text?

Most Unix tools (cut, paste, sed, awk...) read files lines by
line, it's generally a bad idea to have the shell read the file
by itself.

[...]
> while read theline

No, read without any option has a special meaning to the shell

while IFS= read -r theline

> do
>     echo ${theline}

Same thing for echo.

echo -E - $theline # zsh specific
print -r -- "$theline" # ksh/zsh specific

or POSIXLY:

printf '%s\n' "$theline"

>     echo "---------------"
> done < results.txt
[...]

But don't do it, there's probably a much better way to do what
you want to achieve.

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author