From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24483 invoked from network); 3 Sep 2006 17:55:35 -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; 3 Sep 2006 17:55:35 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 30884 invoked from network); 3 Sep 2006 17:55:25 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Sep 2006 17:55:25 -0000 Received: (qmail 27435 invoked by alias); 3 Sep 2006 17:55:18 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10664 Received: (qmail 27426 invoked from network); 3 Sep 2006 17:55:18 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Sep 2006 17:55:18 -0000 Received: (qmail 29907 invoked from network); 3 Sep 2006 17:55:18 -0000 Received: from vms048pub.verizon.net (206.46.252.48) by a.mx.sunsite.dk with SMTP; 3 Sep 2006 17:55:16 -0000 Received: from torch.brasslantern.com ([71.116.118.106]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0J5100FRV33WU7M6@vms048.mailsrvcs.net> for zsh-users@sunsite.dk; Sun, 03 Sep 2006 12:55: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 k83Ht7jB007638 for ; Sun, 03 Sep 2006 10:55:08 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k83Ht7WU007637 for zsh-users@sunsite.dk; Sun, 03 Sep 2006 10:55:07 -0700 Date: Sun, 03 Sep 2006 10:55:07 -0700 From: Bart Schaefer Subject: Re: get array of integers? In-reply-to: <6a42eec70609030959t2a764bfm36fea2c4783f4f01@mail.gmail.com> To: zsh-users@sunsite.dk Message-id: <060903105507.ZM7636@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <6a42eec70609030959t2a764bfm36fea2c4783f4f01@mail.gmail.com> Comments: In reply to "sam reckoner" "get array of integers?" (Sep 3, 9:59am) On Sep 3, 9:59am, sam reckoner wrote: } } I have been doing } } x=$(){1..10} That's a typo? You mean x=( {1..10} ) } Is there a better way? Probably not, except maybe to skip generating the array at all and use a "for (( x=1; x <= 10; ++x ))" loop. Depends on context, of course. (Make sure "x" is not already defined as an array, or that loop will not work properly. Best to explicitly declare "integer x".) } Also, how can I get a range that steps by 2 instead of by 1 as in } } 1 3 5 7 ... By being sneaky. typeset -A x x=( {1..10} ) Now ${(k)x} is an array of odd numbers, and ${(v)x} is an array of even numbers. To get them in ascending order, use ${(nok)x}. Note that you have to assign an even number of numbers, that is x=( {1..9} ) will print an error message and not do the assignment. Of course this trick doesn't work if you want an array by anything other than twos. So a more general approach (if you really want to avoid that "for" loop) would be typeset -a x # Count by 7s from 7 to 70 x=( '$(('{1..10}'*7))' ) x=( ${(e)x} ) # Count by 5s from 1 to 51 x=( '$(('{1..10}'*5+1))' ) x=( 1 ${(e)x} ) Of course you can also get really silly: # Count by 3s from 3 to 30 setopt extendedglob typeset -a x x=( {1..10} ) x=( ${x//(#b)(*)/$(($match*3))} ) That's doing a lot of extra work behind the scenes, though, to match the pattern, store the backreference, etc.