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

Re: Reading line by line

On Wed, Apr 11, 2007 at 03:55:09PM +0900, djh wrote:
> > > meino.cramer@xxxxxx wrote:
> > > >  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.
> I shouldn't think so.  Nothing wrong with reading in lines from a file.
> It should in fact be easier and more efficient than have to load in heavy tools 
> like sed, if they're not needed.  

You're thinking of the shell as of a programming language, not a
shell. A shell is a command line interpreter before all, if you
want to do shell processing *programmatically*, use perl or
ruby, that's what they are good at. Then, use a shell as a
shell, and zsh is the best one at it. You may use while read
loops for speeding up code when writing shell extensions (like
completion functions).

That's my view anyway.

> > > while read theline
> Read "Chapter 17, Shell Builtin Commands"
>      read .. explains all options for the shell builtin "read"
>      getln.. a related function equivalent to "read -zr"

That's to read from the editor buffer stack!

To read a line of input, well all characters til the next
newline character or the end-of-file and store it into a
variable, it's

IFS= read -r line

read foo

is something totally different.


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