From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8342 invoked from network); 16 Aug 2006 07:13:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) 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,UNPARSEABLE_RELAY autolearn=ham version=3.1.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 Aug 2006 07:13:54 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 78131 invoked from network); 16 Aug 2006 07:13:46 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Aug 2006 07:13:46 -0000 Received: (qmail 17997 invoked by alias); 16 Aug 2006 07:13:37 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10613 Received: (qmail 17988 invoked from network); 16 Aug 2006 07:13:36 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 16 Aug 2006 07:13:36 -0000 Received: (qmail 76972 invoked from network); 16 Aug 2006 07:13:36 -0000 Received: from vms040pub.verizon.net (206.46.252.40) by a.mx.sunsite.dk with SMTP; 16 Aug 2006 07:13:32 -0000 Received: from torch.brasslantern.com ([71.121.0.226]) by vms040.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0J4200CG4XC8YLG4@vms040.mailsrvcs.net> for zsh-users@sunsite.dk; Wed, 16 Aug 2006 02:12:09 -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 k7G7C79D009566 for ; Wed, 16 Aug 2006 00:12:08 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k7G7C7ND009565 for zsh-users@sunsite.dk; Wed, 16 Aug 2006 00:12:07 -0700 Date: Wed, 16 Aug 2006 00:12:07 -0700 From: Bart Schaefer Subject: Re: The amazing array feature in zsh In-reply-to: <20060816044842.44532.qmail@web8403.mail.in.yahoo.com> To: Zsh users list Message-id: <060816001207.ZM9564@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <20060816044842.44532.qmail@web8403.mail.in.yahoo.com> Comments: In reply to sac "The amazing array feature in zsh" (Aug 15, 9:49pm) On Aug 15, 9:49pm, sac wrote: } } I discovered this amazing feature of array recently, } assigning values just like we do in some high level } language. Gosh, and here all these years I thought the shell *was* a high-level language. :-) } Here is a example, } } files=() # initialize to null } for mfile in `svn stat $1 | grep '^M' | awk '{ } print $2 }'` } do } files+=($mfile) } done It gets better ... recent versions of zsh can do this: for svncode svnfile in $(svn stat $1) do case $svncode in (M) files+=($svnfile);; esac done } print -c $files # print with tabs } } Notice tha assignment to the array variable +=. I don't know why this isn't discussed under "Array Parameters". It gets a passing mention earlier (as John R. pointed out) but that's only about scalars. Then it's mentioned in a different context under "Subscript Parsing": It is possible to avoid the use of subscripts in assignments to associative array elements by using the syntax: aa+=('key with "*strange*" characters' 'value string') This adds a new key/value pair if the key is not already present, and replaces the value for the existing key if it is. } And actually this can be iterated like, } } for file in $files } do } } done } } I dont know if any other shell provides similar } feature, but this one is too good and useful, and } makes the use of array in shell very easy. But I dont } think this is documented in zsh, atleast I couldn't } find it. The behavior as in "for file in $files" context is described in the "Parameter Expansion" section: If NAME is an array parameter, and the KSH_ARRAYS option is not set, then the value of each element of NAME is substituted, one element per word. Otherwise, the expansion results in one word only; with KSH_ARRAYS, this is the first element of an array. No field splitting is done on the result unless the SH_WORD_SPLIT option is set.