zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: zsh-users@sunsite.dk
Subject: Re: Zsh noob: word-splitting headache
Date: Fri, 7 Jan 2005 12:03:29 +0000	[thread overview]
Message-ID: <20050107120329.GA4550@sc> (raw)
In-Reply-To: <Pine.LNX.4.61.0501041327050.15196@toltec.zanshin.com>

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


      reply	other threads:[~2005-01-07 12:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-04 21:03 kynn
2005-01-04 21:10 ` Clint Adams
2005-01-04 21:35   ` kynn
2005-01-06  2:36   ` Philippe Troin
2005-01-04 21:30 ` Bart Schaefer
2005-01-07 12:03   ` Stephane Chazelas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050107120329.GA4550@sc \
    --to=stephane_chazelas@yahoo.fr \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).