From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13795 invoked from network); 7 Jan 2005 12:02:39 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 7 Jan 2005 12:02:39 -0000 Received: (qmail 20230 invoked from network); 7 Jan 2005 12:02:29 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 7 Jan 2005 12:02:29 -0000 Received: (qmail 25645 invoked by alias); 7 Jan 2005 12:02:21 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8339 Received: (qmail 25629 invoked from network); 7 Jan 2005 12:02:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 7 Jan 2005 12:02:20 -0000 Received: (qmail 19164 invoked from network); 7 Jan 2005 12:02:20 -0000 Received: from smtp-out2.blueyonder.co.uk (195.188.213.5) by a.mx.sunsite.dk with SMTP; 7 Jan 2005 12:02:17 -0000 Received: from sc ([82.41.236.30]) by smtp-out2.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Fri, 7 Jan 2005 12:02:48 +0000 Date: Fri, 7 Jan 2005 12:03:29 +0000 From: Stephane Chazelas To: zsh-users@sunsite.dk Subject: Re: Zsh noob: word-splitting headache Message-ID: <20050107120329.GA4550@sc> Mail-Followup-To: zsh-users@sunsite.dk References: <200501042103.j04L3KU19128@panix3.panix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.6i X-OriginalArrivalTime: 07 Jan 2005 12:02:48.0682 (UTC) FILETIME=[CE5CB4A0:01C4F4B0] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.1 required=6.0 tests=HTML_MESSAGE autolearn=no version=2.63 X-Spam-Hits: 0.1 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]} <> <> -- Stéphane