From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26432 invoked by alias); 2 Nov 2015 00:01:29 -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: 20868 Received: (qmail 4020 invoked from network); 2 Nov 2015 00:01:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1446422151; bh=dx0DfoFI3dOFCPamJp01kUOlNZaUrGJ87DpojWI+xuM=; h=From:To:In-Reply-To:References:Subject:Date; b=mW1HVX5PjFLRmERSxFxvTcLzdH1fnfeFTA9IEU4Gl7e4uCSSMD3F0gF2XFt1HVOoW Nj431zkl+YqidHPKMn2BBitCGqyk9rabeuOAF+sS5IUAjAH1XfCA8uBopyPSPPvDbg goM6tzuZHbt2P7PbEldQaAzUV8Utzr06Kg5WaKT0= From: ZyX To: Ray Andrews , Zsh Users In-Reply-To: <56369C7B.2030604@eastlink.ca> References: <56369C7B.2030604@eastlink.ca> Subject: Re: easy calling of associative array? MIME-Version: 1.0 Message-Id: <1237641446422150@web6m.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 02 Nov 2015 02:55:50 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r 02.11.2015, 02:44, "Ray Andrews" : > test () > { > ššššševal "baz=\$${1}[key1]" > šššššecho $baz > eval "foo=\$${1}[key2]" > šššššecho $foo > ... > } > > If I want to pass the name of an associative array to a function via > "$1" and then work with it's keys, the above succeeds but it's sure > laborious. Is there some way to do the eval just once? So that I can > end up doing: > > if [ "xyz[key1]" = '1' ]; then ... > > ... as I experiment, there seems to be no way of replacing 'xyz' with > any expression that will do the job without needing eval's help every > time, but I'll bet there's a way. There is ${(P)} for indirect referencing: % foo=path % echo ${${(P)foo}[1]} $path[1] /home/zyx/.local/bin /home/zyx/.local/bin . This is in `man zshexpn`.