From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17479 invoked by alias); 14 Jul 2013 13:10:43 -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: 17868 Received: (qmail 29573 invoked from network); 14 Jul 2013 13:10:29 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.223.182 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=d8MawtpcdoF4ncyFngbIb9ZCMx56Y6auXVDVi51oLbU=; b=yEhp5GNiOgY+DNGShOGhha0fAndhX+SuujUmPvXfU2jq774JA0D7wZHWQXTbUxA/ss uhOuQPeUUkbljJjVLGLV4UVvdPM5t0vEpLcSwarHnCkRK4BWRFeIc3KFRHoCzjZIuENd mq6G94AHWYof2F4m7ZIlbJbpRDn0Uam7+8CzwCpe21+3+u8B7COc2+uh5LkuG0f43Nln Tut9b8b7bYBt35cbLfmnBVu8Jrod8tIJBEhrGOnEdFY7U5WMg5YElxV9lcvqg0PvhKw0 AYcj7xbBiCoZ95XUBloWegaQh6mClYFU2IHt03SvM8K7P+7rOLAmLIWNieKQJ65Pz6e4 vntg== MIME-Version: 1.0 X-Received: by 10.50.32.10 with SMTP id e10mr4766912igi.10.1373807422729; Sun, 14 Jul 2013 06:10:22 -0700 (PDT) In-Reply-To: References: Date: Sun, 14 Jul 2013 15:10:22 +0200 Message-ID: Subject: Re: How to iterate over an array of associative arrays From: Mikael Magnusson To: Thorsten Kampe Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On 14 July 2013 14:35, Thorsten Kampe wrote: > Hi, > > I'd like to iterate over elements of an array. The elements are > associative arrays. This is my code: > > """ > #! /usr/bin/env zsh > emulate -R zsh > > setopt nounset > > declare -A elem AssocArr1 AssocArr2 > > AssocArr1=(key value1) > AssocArr2=(key value2) > > array=($AssocArr1 $AssocArr2) Do you really want these $ here? > for elem in $array > do echo $elem[key] > done > """ > > ./test.zsh:14: elem[key]: parameter not set You need to use the (P) flag to access a parameter indirectly. % foo=(one two) % bar=foo % echo $bar[2] o % echo ${${bar}[2]} o % echo ${${(P)bar}[2]} two -- Mikael Magnusson