Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Iterating over a set of arrays
- X-seq: zsh-users 18890
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Iterating over a set of arrays
- Date: Mon, 09 Jun 2014 11:20:30 +0100
- In-reply-to: <ln40u0$bio$1@ger.gmane.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <ln40u0$bio$1@ger.gmane.org>
On Mon, 09 Jun 2014 12:05:51 +0200
Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author