From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16683 invoked by alias); 9 Jun 2014 10:30:41 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18890 Received: (qmail 4587 invoked from network); 9 Jun 2014 10:30:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7fac6d000006cfe-85-53958a6fc105 Date: Mon, 09 Jun 2014 11:20:30 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Iterating over a set of arrays Message-id: <20140609112030.4756935f@pwslap01u.europe.root.pri> In-reply-to: References: Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupiluLIzCtJLcpLzFFi42I5/e/4Zd38rqnBBu+m81vsOLmS0YHRY9XB D0wBjFFcNimpOZllqUX6dglcGTeaLzIWLGKtmP3yOnsD4z/mLkZODgkBE4kzk66yQNhiEhfu rWcDsYUEljJK9E4V72LkArGZJC42zwZLsAioSlyadpIJxGYTMJSYumk2I4gtIiAqsXzFZnYQ W1hAW6Ltzj6gBRwcvAL2EgsuGIKEOQU0JRp2TmYBCQsJaEi0bvMDCfML6Etc/fuJCeIEe4mZ V86ATeQVEJT4Mfke2GnMAloSm7c1sULY8hKb17xlnsAoMAtJ2SwkZbOQlC1gZF7FKJpamlxQ nJSea6hXnJhbXJqXrpecn7uJERJ+X3YwLj5mdYhRgINRiYc3g3NqsBBrYllxZe4hRgkOZiUR Xp8coBBvSmJlVWpRfnxRaU5q8SFGJg5OqQbGiRw9mqd/inMbNBsF85hsz3+sxrbY/Ib+jEA7 l91HJb6w929c/dp/w0y3jzwX5x7XSV/M1XYiYeq59w4xXu+0J25pZpjhKmM+50Mi08XkOx+7 /6yMOC8YW/ksab/WllPG01mFPXKP8x7RkrovummVkuNygfJgqTsflCsTfA+YK4Q/Flv3i/eC EktxRqKhFnNRcSIA0+zQ0B0CAAA= On Mon, 09 Jun 2014 12:05:51 +0200 Thorsten Kampe wrote: > this is originally a bash question but I'd also be interested in a > zsh solution (or if there is no solution). > > I'd like to get the second element of a set of arrays. > > arrayA=(a1 a2 a3) > arrayB=(b1 b2 b3) > arrayC=(c1 c2 c3) > > The output should be > > a2 > b2 > c2 The (P) flag does what you want. Remember the array indexing is (by default) different from bash. for a in array{A,B,C}; do print ${${(P)a}[2]} done You need the extra braces to ensure the result of the name substitution gets the index, not the original variable. pws