From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18154 invoked from network); 10 May 2006 17:29:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 10 May 2006 17:29:26 -0000 Received: (qmail 66780 invoked from network); 10 May 2006 17:29:18 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 10 May 2006 17:29:18 -0000 Received: (qmail 23025 invoked by alias); 10 May 2006 17:29:11 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10239 Received: (qmail 23016 invoked from network); 10 May 2006 17:29:11 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 10 May 2006 17:29:11 -0000 Received: (qmail 65791 invoked from network); 10 May 2006 17:29:11 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 10 May 2006 17:29:09 -0000 Received: from torch.brasslantern.com ([71.116.81.67]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IZ2009I38K4GUR0@vms044.mailsrvcs.net> for zsh-users@sunsite.dk; Wed, 10 May 2006 12:29:03 -0500 (CDT) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id k4AHSIGQ011452 for ; Wed, 10 May 2006 10:28:47 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k4AHSIWp011451 for zsh-users@sunsite.dk; Wed, 10 May 2006 10:28:18 -0700 Date: Wed, 10 May 2006 10:28:18 -0700 From: Bart Schaefer Subject: Re: Parameter expansion flags question In-reply-to: To: Message-id: <060510102818.ZM11450@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: Comments: In reply to "John Cooper" "Parameter expansion flags question" (May 10, 10:22am) On May 10, 10:22am, John Cooper wrote: } } delsites() { } for site in "${(f)$($SITEMGR -i)}" ; { } sitepath=${${=site}[1]} } [[ -n "$sitepath" ]] && $SITEMGR -r "WICurrent=$sitepath" } } } } } } I'm new to the zsh parameter expansion flags, but I've gathered the } ${(f) will take the command's output a line at a time, and the ${=site} } will then split each line into words, allowing me to grab the first word } of each line. Right so far. } Is there a better (or simpler!) way to do this? You might consider using the "read" builtin: $SITEMGR -i | while read -A site; { $SITEMGR -r "WICurrent=${site[1]}" } Or: $SITEMGR -i | while read sitepath stuff_to_discard; { $SITEMGR -r "WICurrent=$sitepath" } If you still want to use expansion, you can combine the expansions: for sitepath in ${${=${(f)"$($SITEMGR -i)"}}[1]} Be warned, however, that ${=var} is not guaranteed to produce an array; if any line in the $SITEMGR output has only one word in it, the result of the above will be the first *character* of the line, not the first *word*. The solutions with "read" do not have this problem. } When the command has no output, the `for' loop is still executed once } (seemingly because the command is within double-quotes) and is the } reason for checking that the length of $sitepath is non-zero. Is there } a way to avoid the loop being entered when the command has no output } and avoid the need for this check? Change the expansion to have it discard all empty array elements by using the ":#pattern" operator with an empty pattern: for sitepath in ${${=${(f)"$($SITEMGR -i)":#}}[1]} } (btw, is there a good set of examples of using parameter expansion } flags? The zsh guide seemed a bit sparse in this area) Other than in the archives of this list, not that I'm aware of. Did you look around on zshwiki.org?