Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Zsh noob: word-splitting headache
- X-seq: zsh-users 8339
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Zsh noob: word-splitting headache
- Date: Fri, 7 Jan 2005 12:03:29 +0000
- In-reply-to: <Pine.LNX.4.61.0501041327050.15196@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <200501042103.j04L3KU19128@xxxxxxxxxxxxxxxx> <Pine.LNX.4.61.0501041327050.15196@xxxxxxxxxxxxxxxxxx>
On Tue, Jan 04, 2005 at 01:30:44PM -0800, Bart Schaefer wrote:
[...]
> foo | while read i; do something with $i; done
foo | while IFS= read -r i; do something with "$i"; done
or leading and trailing blanks would be stripped, and backslash
would be treated specially.
Note that this means that "something" stdin is modified.
The quotes around "$i" are here in case there are empty lines.
Note that in
for i in ${(f)"$(foo)"}
or
IFS=$'\n'
for i in $(foo)
The empty lines are discarded.
To avoid that, you can do:
IFS=$'\n\n'
for i in $(foo)
But still, because of the (to my mind bogus) way command
substitution works in Bourne like shells, the empty lines at the
end of foo output will still be discarded. To prevent that, you
can do:
IFS=$'\n\n'
for i in ${$(foo; echo .)[1,-2]}
$ printf '<%s>\n' ${$(echo 'a b\n\n'; echo .)[1,-2]}
<a b>
<>
<>
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author