From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3820 invoked from network); 10 May 2006 09:22:56 -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=BAYES_00,FORGED_RCVD_HELO, HTML_MESSAGE 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 09:22:56 -0000 Received: (qmail 51815 invoked from network); 10 May 2006 09:22:40 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 10 May 2006 09:22:40 -0000 Received: (qmail 14529 invoked by alias); 10 May 2006 09:22:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10233 Received: (qmail 14518 invoked from network); 10 May 2006 09:22:31 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 10 May 2006 09:22:31 -0000 Received: (qmail 50661 invoked from network); 10 May 2006 09:22:31 -0000 Received: from smtp.eu.citrix.com (195.153.38.115) by a.mx.sunsite.dk with SMTP; 10 May 2006 09:22:30 -0000 Received: from lonpexchmx01.citrite.net ([10.30.224.191]) by SMTP.EU.CITRIX.COM with ESMTP; 10 May 2006 10:22:13 +0100 X-IronPort-AV: i="4.05,108,1146438000"; d="scan'208,217"; a="5078543:sNHT58289720" Received: from lonpexch01.citrite.net ([10.30.224.136]) by lonpexchmx01.citrite.net with Microsoft SMTPSVC(6.0.3790.1830); Wed, 10 May 2006 10:22:12 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C67413.384B2AFB" Subject: Parameter expansion flags question Date: Wed, 10 May 2006 10:22:12 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Parameter expansion flags question Thread-Index: AcZ0EzhN8LTv/NUXSdqKylXHm/HXgA== From: "John Cooper" To: X-OriginalArrivalTime: 10 May 2006 09:22:12.0901 (UTC) FILETIME=[38933550:01C67413] This is a multi-part message in MIME format. ------_=_NextPart_001_01C67413.384B2AFB Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I've been writing a function to run a command, extract the first word of each line of the command's output and use that as a parameter to another command. The command's output looks like this: 1:/Citrix/Pres WI http://RA.eng.citrite.net/Citrix/Pres 4.5.5.1159 c:\inetpub\wwwroot\Citrix\Pres =20 1:/Citrix/Pres2 WI http://RA.eng.citrite.net/Citrix/Pres2 4.5.5.1159 c:\inetpub\wwwroot\Citrix\Pres2=20 After some trial-and-error I finally have the following function: SITEMGR=3Dc:/Program\ Files/Citrix/Web\ Interface/4.5/sitemgr.exe delsites() { for site in "${(f)$($SITEMGR -i)}" ; { sitepath=3D${${=3Dsite}[1]} [[ -n "$sitepath" ]] && $SITEMGR -r "WICurrent=3D$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 = ${=3Dsite} will then split each line into words, allowing me to grab the first word of each line. Is there a better (or simpler!) way to do this? 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? (btw, is there a good set of examples of using parameter expansion flags? The zsh guide seemed a bit sparse in this area) Thanks, --- John ------_=_NextPart_001_01C67413.384B2AFB Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Parameter expansion flags question

Ive been = writing a function to run a = command, extract the first word of each line of = the = commands output and use that as a parameter to = another command. The commands output looks like = this:

After some trial-and-error I finally have the following = function:

      SITEMGR=3Dc:/Program\ Files/Citrix/Web\ = Interface/4.5/sitemgr.exe

      delsites() {

          for site in "${(f)$($SITEMGR = -i)}" ; {

              sitepath=3D${${=3Dsite}[1]}

              [[ -n "$sitepath" ]] && $SITEMGR -r = "WICurrent=3D$sitepath"

          }

      }

Im new to = the = zsh = parameter expansion flags, but Ive gathered the ${(f) will take the = commands output a line at a time, and the = ${=3Dsite} will then split each line into words, allowing me to = grab the first word of each line.

Is = there a better (or simpler!) way to do this?  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?

(btw, is there a good set of examples of using parameter = expansion flags? The zsh guide seemed a bit sparse in this = area)

Thanks,

    --- = John

------_=_NextPart_001_01C67413.384B2AFB-- 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? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2244 invoked from network); 11 May 2006 10:00:09 -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; 11 May 2006 10:00:09 -0000 Received: (qmail 5045 invoked from network); 11 May 2006 09:59:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 May 2006 09:59:56 -0000 Received: (qmail 26743 invoked by alias); 11 May 2006 09:59:49 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10244 Received: (qmail 26734 invoked from network); 11 May 2006 09:59:48 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 May 2006 09:59:48 -0000 Received: (qmail 3989 invoked from network); 11 May 2006 09:59:48 -0000 Received: from smtp.eu.citrix.com (195.153.38.115) by a.mx.sunsite.dk with SMTP; 11 May 2006 09:59:46 -0000 Received: from lonpexchmx01.citrite.net ([10.30.224.191]) by SMTP.EU.CITRIX.COM with ESMTP; 11 May 2006 10:59:30 +0100 X-IronPort-AV: i="4.05,113,1146438000"; d="scan'208"; a="5095008:sNHT62235124" Received: from lonpexch01.citrite.net ([10.30.224.136]) by lonpexchmx01.citrite.net with Microsoft SMTPSVC(6.0.3790.1830); Thu, 11 May 2006 10:59:29 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Parameter expansion flags question Date: Thu, 11 May 2006 10:59:29 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Parameter expansion flags question Thread-Index: AcZ0V0aIxJ4OeQMOS+6h5AnbpczpgAAhfsaQ From: "John Cooper" To: "Bart Schaefer" , X-OriginalArrivalTime: 11 May 2006 09:59:29.0809 (UTC) FILETIME=[984A0810:01C674E1] Bart, Thanks for the detailed reply - it seems using "read" is the most straightforward approach. However, in the interests of learning more about expansions, I've been trying your suggestions and they don't seem to work as expected. $ $SITEMGR -i 1:/Citrix/Pres WI http://RA.eng.citrite.net/Citrix/Pres 4.5.5.1159 c:\inetpub\wwwroot\Citrix\Pres =20 1:/Citrix/Pres2 WI http://RA.eng.citrite.net/Citrix/Pres2 4.5.5.1159 c:\inetpub\wwwroot\Citrix\Pres2=20 (not sure if Outlook will wrap the above, but the output is actually 2 lines, each starting "1:/Citrix") My original function correctly finds the first word of both lines: $ type delsites2 delsites2 () { for site in "${(f)$($SITEMGR -i)}" do sitepath=3D${${=3Dsite}[1]}=20 echo "sitepath is $sitepath" done } $ delsites2 sitepath is 1:/Citrix/Pres sitepath is 1:/Citrix/Pres2 $ However, when the expansions are combined, it only finds the first word of the first line: $ type delsites3 delsites3 () { for sitepath in ${${=3D${(f)"$($SITEMGR -i)"}}[1]} do echo "sitepath is $sitepath" done } $ delsites3 sitepath is 1:/Citrix/Pres $ If I add the ":#pattern" operator to the original function, the "for" loop is still executed once in the case where $SITEMGR produces no output: $ type delsites4 delsites4 () { for site in "${(f)$($SITEMGR -i):#}" do sitepath=3D${${=3Dsite}[1]}=20 echo sitepath is "$sitepath" done } $ delsites $ $SITEMGR -i $ $ delsites4 sitepath is=20 $ =20 One final thing - when I entered the "read" example into the shell as stated I got syntax errors. These were resolved by using "do" and "done" instead of braces - is this to be expected? $ $SITEMGR -i 1:/Citrix/Pres WI http://RA.eng.citrite.net/Citrix/Pres 4.5.5.1159 c:\inetpub\wwwroot\Citrix\Pres =20 $ $SITEMGR -i | while read -A site; { pipe while cursh> echo $site =20 pipe while cursh> } pipe while> } zsh: parse error near `}' $ $ $SITEMGR -i | while read -A site; do pipe while> echo $site pipe while> done 1:/Citrix/Pres WI http://RA.eng.citrite.net/Citrix/Pres 4.5.5.1159 c:inetpubwwwrootCitrixPres=20 $ I'm using zsh 4.2.6 on cygwin/WinXP. --- John -----Original Message----- From: Bart Schaefer [mailto:schaefer@brasslantern.com]=20 Sent: 10 May 2006 18:28 To: zsh-users@sunsite.dk Subject: Re: Parameter expansion flags question On May 10, 10:22am, John Cooper wrote: } } delsites() { } for site in "${(f)$($SITEMGR -i)}" ; { } sitepath=3D${${=3Dsite}[1]} } [[ -n "$sitepath" ]] && $SITEMGR -r "WICurrent=3D$sitepath" } } } } }=20 } 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 ${=3Dsite} } 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=3D${site[1]}" } Or: $SITEMGR -i | while read sitepath stuff_to_discard; { $SITEMGR -r "WICurrent=3D$sitepath" } If you still want to use expansion, you can combine the expansions: for sitepath in ${${=3D${(f)"$($SITEMGR -i)"}}[1]} Be warned, however, that ${=3Dvar} 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 ${${=3D${(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? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24099 invoked from network); 11 May 2006 16:39:22 -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; 11 May 2006 16:39:22 -0000 Received: (qmail 79965 invoked from network); 11 May 2006 16:39:16 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 May 2006 16:39:16 -0000 Received: (qmail 8625 invoked by alias); 11 May 2006 16:39:08 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10249 Received: (qmail 8616 invoked from network); 11 May 2006 16:39:08 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 May 2006 16:39:08 -0000 Received: (qmail 78874 invoked from network); 11 May 2006 16:39:07 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 11 May 2006 16:39:07 -0000 Received: from torch.brasslantern.com ([71.116.105.50]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IZ400M7U0WCSE0G@vms048.mailsrvcs.net> for zsh-users@sunsite.dk; Thu, 11 May 2006 11:38:37 -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 k4BGcaQo013209 for ; Thu, 11 May 2006 09:38:36 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k4BGcZCk013208 for zsh-users@sunsite.dk; Thu, 11 May 2006 09:38:35 -0700 Date: Thu, 11 May 2006 09:38:35 -0700 From: Bart Schaefer Subject: Re: Parameter expansion flags question In-reply-to: To: Message-id: <060511093835.ZM13207@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" "RE: Parameter expansion flags question" (May 11, 10:59am) [skipping around a bit] On May 11, 10:59am, John Cooper wrote: } } One final thing - when I entered the "read" example into the shell as } stated I got syntax errors. These were resolved by using "do" and "done" } instead of braces - is this to be expected? Yeah, I messed up. I never use the form with the braces, but you did in your original "for" sample, so I tried to keep it with "while". I forgot that for "while" loops it only works when the first condition is [[ ... ]] or (( ... )). } Thanks for the detailed reply - it seems using "read" is the most } straightforward approach. However, in the interests of learning more } about expansions, I've been trying your suggestions and they don't seem } to work as expected. Oh, duh. I spaced that there were multiple lines of output from the $SITEMGR program. Obviously you need to process each line separately before applying the subscript. (This cold I'm coming down with must be affecting me worse than I thought.) } If I add the ":#pattern" operator to the original function, the "for" } loop is still executed once in the case where $SITEMGR produces no } output: } delsites4 () { } for site in "${(f)$($SITEMGR -i):#}" Placement of the quotes is important: for site in ${(f)"$($SITEMGR -i)":#} If it still happens, I think it's because of Cygwin line termination. Instead of an empty string when splitting with (f), you're getting a string having a single carriage-return character. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21131 invoked from network); 12 May 2006 11:03:05 -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; 12 May 2006 11:03:05 -0000 Received: (qmail 6778 invoked from network); 12 May 2006 11:02:57 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 May 2006 11:02:57 -0000 Received: (qmail 3271 invoked by alias); 12 May 2006 11:02:47 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10253 Received: (qmail 3261 invoked from network); 12 May 2006 11:02:46 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 May 2006 11:02:46 -0000 Received: (qmail 5474 invoked from network); 12 May 2006 11:02:46 -0000 Received: from smtp.eu.citrix.com (195.153.38.115) by a.mx.sunsite.dk with SMTP; 12 May 2006 11:02:44 -0000 Received: from lonpexchmx01.citrite.net ([10.30.224.191]) by SMTP.EU.CITRIX.COM with ESMTP; 12 May 2006 12:02:31 +0100 X-IronPort-AV: i="4.05,120,1146438000"; d="scan'208"; a="5112463:sNHT49222268" Received: from lonpexch01.citrite.net ([10.30.224.136]) by lonpexchmx01.citrite.net with Microsoft SMTPSVC(6.0.3790.1830); Fri, 12 May 2006 12:02:31 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Parameter expansion flags question Date: Fri, 12 May 2006 12:02:30 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Parameter expansion flags question Thread-Index: AcZ1GXNmz7MK2yRoTW2xDBg8JmO+gQAmSDUg From: "John Cooper" To: "Bart Schaefer" , X-OriginalArrivalTime: 12 May 2006 11:02:31.0474 (UTC) FILETIME=[90C01120:01C675B3] > Placement of the quotes is important: > for site in ${(f)"$($SITEMGR -i)":#} OK, changing the placement of the quotes to the above fixes it. There's just one thing I'm a little puzzled about - in the case where $SITEMGR produces no output, won't "$($SITEMGR -i)" be the empty string? If so, why is :# needed? It seems it will just replace an empty string with another empty string? Thanks, --- John -----Original Message----- From: Bart Schaefer [mailto:schaefer@brasslantern.com]=20 Sent: 11 May 2006 17:39 To: zsh-users@sunsite.dk Subject: Re: Parameter expansion flags question [skipping around a bit] On May 11, 10:59am, John Cooper wrote: } } One final thing - when I entered the "read" example into the shell as } stated I got syntax errors. These were resolved by using "do" and "done" } instead of braces - is this to be expected? Yeah, I messed up. I never use the form with the braces, but you did in your original "for" sample, so I tried to keep it with "while". I forgot that for "while" loops it only works when the first condition is [[ ... ]] or (( ... )). } Thanks for the detailed reply - it seems using "read" is the most } straightforward approach. However, in the interests of learning more } about expansions, I've been trying your suggestions and they don't seem } to work as expected. Oh, duh. I spaced that there were multiple lines of output from the $SITEMGR program. Obviously you need to process each line separately before applying the subscript. (This cold I'm coming down with must be affecting me worse than I thought.) } If I add the ":#pattern" operator to the original function, the "for" } loop is still executed once in the case where $SITEMGR produces no } output: } delsites4 () { } for site in "${(f)$($SITEMGR -i):#}" Placement of the quotes is important: for site in ${(f)"$($SITEMGR -i)":#} If it still happens, I think it's because of Cygwin line termination. Instead of an empty string when splitting with (f), you're getting a string having a single carriage-return character. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8988 invoked from network); 12 May 2006 14:45:36 -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; 12 May 2006 14:45:36 -0000 Received: (qmail 6379 invoked from network); 12 May 2006 14:45:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 May 2006 14:45:28 -0000 Received: (qmail 12144 invoked by alias); 12 May 2006 14:45:21 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10255 Received: (qmail 12135 invoked from network); 12 May 2006 14:45:21 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 May 2006 14:45:21 -0000 Received: (qmail 5387 invoked from network); 12 May 2006 14:45:20 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 12 May 2006 14:45:19 -0000 Received: from torch.brasslantern.com ([71.116.105.50]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IZ5002AEQBFTVO1@vms048.mailsrvcs.net> for zsh-users@sunsite.dk; Fri, 12 May 2006 09:45:16 -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 k4CEjFVV015615 for ; Fri, 12 May 2006 07:45:15 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k4CEjFi0015614 for zsh-users@sunsite.dk; Fri, 12 May 2006 07:45:15 -0700 Date: Fri, 12 May 2006 07:45:15 -0700 From: Bart Schaefer Subject: Re: Parameter expansion flags question In-reply-to: To: Message-id: <060512074515.ZM15613@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" "RE: Parameter expansion flags question" (May 12, 12:02pm) On May 12, 12:02pm, John Cooper wrote: } Subject: RE: Parameter expansion flags question } } > Placement of the quotes is important: } > for site in ${(f)"$($SITEMGR -i)":#} } } OK, changing the placement of the quotes to the above fixes it. There's } just one thing I'm a little puzzled about - in the case where $SITEMGR } produces no output, won't "$($SITEMGR -i)" be the empty string? If so, } why is :# needed? It seems it will just replace an empty string with } another empty string? It's the same as the difference between string="" array=( word "$string" word ) print $#array and string="" array=( word $string word ) print $#array An unquoted empty string is discarded; a quoted empty string is retained. Effectively the :# construct discards the quoted empty string, leaving an unquoted one in its place, which the shell in turn discards when building the final array. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22514 invoked from network); 15 May 2006 09:02:15 -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; 15 May 2006 09:02:15 -0000 Received: (qmail 38220 invoked from network); 15 May 2006 09:02:06 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 May 2006 09:02:06 -0000 Received: (qmail 768 invoked by alias); 15 May 2006 09:01:56 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10265 Received: (qmail 758 invoked from network); 15 May 2006 09:01:55 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 May 2006 09:01:55 -0000 Received: (qmail 37225 invoked from network); 15 May 2006 09:01:55 -0000 Received: from smtp.eu.citrix.com (195.153.38.115) by a.mx.sunsite.dk with SMTP; 15 May 2006 09:01:53 -0000 Received: from lonpexchmx01.citrite.net ([10.30.224.191]) by SMTP.EU.CITRIX.COM with ESMTP; 15 May 2006 10:01:38 +0100 X-IronPort-AV: i="4.05,128,1146438000"; d="scan'208"; a="5134555:sNHT39867108" Received: from lonpexch01.citrite.net ([10.30.224.136]) by lonpexchmx01.citrite.net with Microsoft SMTPSVC(6.0.3790.1830); Mon, 15 May 2006 10:01:37 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: Parameter expansion flags question Date: Mon, 15 May 2006 10:01:36 +0100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Parameter expansion flags question Thread-Index: AcZ10sGySQdhosY1Sle2cQcJzcPSMQCK12ug From: "John Cooper" To: "Bart Schaefer" , X-OriginalArrivalTime: 15 May 2006 09:01:37.0515 (UTC) FILETIME=[2C4B03B0:01C677FE] Ah, I see. Thanks again for all the help. --- John -----Original Message----- From: Bart Schaefer [mailto:schaefer@brasslantern.com]=20 Sent: 12 May 2006 15:45 To: zsh-users@sunsite.dk Subject: Re: Parameter expansion flags question On May 12, 12:02pm, John Cooper wrote: } Subject: RE: Parameter expansion flags question } } > Placement of the quotes is important: } > for site in ${(f)"$($SITEMGR -i)":#} }=20 } OK, changing the placement of the quotes to the above fixes it. There's } just one thing I'm a little puzzled about - in the case where $SITEMGR } produces no output, won't "$($SITEMGR -i)" be the empty string? If so, } why is :# needed? It seems it will just replace an empty string with } another empty string? It's the same as the difference between string=3D"" array=3D( word "$string" word ) print $#array and string=3D"" array=3D( word $string word ) print $#array An unquoted empty string is discarded; a quoted empty string is retained. Effectively the :# construct discards the quoted empty string, leaving an unquoted one in its place, which the shell in turn discards when building the final array.