From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6708 invoked from network); 25 Apr 2006 14:42:03 -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; 25 Apr 2006 14:42:03 -0000 Received: (qmail 55729 invoked from network); 25 Apr 2006 14:41:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 Apr 2006 14:41:56 -0000 Received: (qmail 14806 invoked by alias); 25 Apr 2006 14:41:49 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10185 Received: (qmail 14797 invoked from network); 25 Apr 2006 14:41:48 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 25 Apr 2006 14:41:48 -0000 Received: (qmail 54520 invoked from network); 25 Apr 2006 14:41:48 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 25 Apr 2006 14:41:48 -0000 Received: from torch.brasslantern.com ([71.116.76.26]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IYA00K808TM2UA0@vms048.mailsrvcs.net> for zsh-users@sunsite.dk; Tue, 25 Apr 2006 09:41:47 -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 k3PEfj7F001846 for ; Tue, 25 Apr 2006 07:41:45 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k3PEfjqi001845 for zsh-users@sunsite.dk; Tue, 25 Apr 2006 07:41:45 -0700 Date: Tue, 25 Apr 2006 07:41:45 -0700 From: Bart Schaefer Subject: Re: Style question: Can this be written in a more elegant way? In-reply-to: <444DD5D8.2030409@ulpmm.u-strasbg.fr> To: zsh-users@sunsite.dk Message-id: <060425074145.ZM1844@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <6F0CB04509C11D46A54232E852E390AC013D956D@MCHP7R6A.ww002.siemens.net> <444C8C0B.6090409@ulpmm.u-strasbg.fr> <060424082135.ZM390@torch.brasslantern.com> <444DD5D8.2030409@ulpmm.u-strasbg.fr> Comments: In reply to Marc Chantreux "Re: Style question: Can this be written in a more elegant way?" (Apr 25, 9:55am) On Apr 25, 9:55am, Marc Chantreux wrote: } Subject: Re: Style question: Can this be written in a more elegant way? } } > } file=( *(om) ) } > } (( $file[1] )) && PROG_SUCCESS || PROG_FAIL } > } > I think you mean: } > } > file=( X*(Nom[1]) ) } > (( $+file )) && PROG_SUCCESS $file || PROG_FAIL } } I didn't : my lines was the best i've found. But (( $file[1] )) can't be right; it treats the file name as a math expression, so a file named "3-3" would execute PROG_FAIL. You must at least mean (( ${+file[1]} )). } is there a reason to not use the next line ? } } if (( $+file )) { PROG_SUCCESS $file } else { PROG_FAIL } It's a syntax error in other Bourne-like shells, and some of us are habituated to write the portable constructs even when we're mixing them with non-portable ones. } BTW, i've tried another way to launch PROG_SUCCESS for the first file } but it failed because it execute the e:: code for all the files. Peraps } there is a trick i missed? No, the meaning of (e:...:) is that the result of executing the commands determines whether or not the file participates in the glob result. So the commands must be executed for every file, and this happens before the sorting. In this example ... } % ls } is score the this } % : *(Nom[1]e:echo last file $REPLY:) } last file score } last file score } last file score } last file score ... you have failed to quote $REPLY so it substitutes the value that it had before the glob began to execute. It's as if you had typed: % : *(Nom[1]e:echo last file score:) Correct is like so: % : *(Nom[1]e:'echo last file $REPLY':) last file this last file is last file the last file score