Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Reading line by line
- X-seq: zsh-users 11386
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Micah Cowan <micah@xxxxxxxxxx>
- Subject: Re: Reading line by line
- Date: Wed, 11 Apr 2007 19:36:02 +0100
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <461D2541.1080104@xxxxxxxxxx>
- Mail-followup-to: Micah Cowan <micah@xxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <242911.74922.qm@xxxxxxxxxxxxxxxxxxxxxxxxx> <461D2541.1080104@xxxxxxxxxx>
On Wed, Apr 11, 2007 at 11:13:21AM -0700, Micah Cowan wrote:
> sac wrote:
> > 2. Like Micah J. Cowan pointed out,
> >
> > while read i
> > do
> > echo $i
> > done < filename
>
> As Stephane points out, -r is preferable, as it disables
> backslash-escaping. IFS= should not be necessary--and isn't, in zsh--but
> dash, bash and ksh all violate POSIX (as I read it) by inserting new
> field separators after splitting, instead of using the original
> separation; so using IFS= is portable.
[...]
Don't know what you mean, but IFS= is necessary even with zsh,
and the behavior is POSIX in every shell AFAICT, could you
please expand.
$ echo ' a ' | read -r
$ echo "<$REPLY>"
<a>
$ echo ' a ' | IFS= read -r
$ echo "<$REPLY>"
< a >
zsh also has:
IFS=$'\n\n' read -rAd '' argv
argv=("${(@)argv[1,-2]}")
for i do
print -r -- $i
done
Or to loop over non-empty lines:
for i in ${(f)"$(cat filename)"}; do
print -r -- $i
done
Myself, I go for
@lines = <>;
or
while (<>)
or
perl -ne '...'
:)
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author