From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6743 invoked by alias); 26 Jan 2015 20:00:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34405 Received: (qmail 14638 invoked from network); 26 Jan 2015 20:00:40 -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 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=cD07yEoTFS6exy7sudPrW3WXMBi3gYiFx2sMFo8K7ks=; b=WuFyzgnjvoH2cWeEMj03gPAddnZCxAJjoco7640fBYzh5sH958E2qTLsZqRKSWVidh eKBHFmRK8K3Pglasay5jK8+lFfVs/EMLyEiJrFic3do5wgeSv2QDEdHrECywWnBYZEQN 6MPTCtRC3IePhYEN3THEid7VHDfEnYvMEZkRg8NxE72Q0/T35uWhvqxDBlpT84i9xT4V eP5gQQCp+Mirna7EN/6JhXEekXZdTfoaAaE8B3gyy1SM11vHyyIAr8tx0u53jjvga0Jo JqLjeQJ3FTEb1bsApgLt63jde5dtbFu+Jmg6BZNouj9wqodOSE3IxsKLOBmfvrhOCTT5 veHQ== MIME-Version: 1.0 X-Received: by 10.50.32.7 with SMTP id e7mr18203621igi.21.1422302434626; Mon, 26 Jan 2015 12:00:34 -0800 (PST) In-Reply-To: <150125133931.ZM32124@torch.brasslantern.com> References: <1422177338-85472-1-git-send-email-tomoki.sekiyama@gmail.com> <150125122410.ZM31619@torch.brasslantern.com> <10496951422218331@web21g.yandex.ru> <150125133931.ZM32124@torch.brasslantern.com> Date: Mon, 26 Jan 2015 15:00:34 -0500 Message-ID: Subject: Re: [PATCH] Enable further expansion of parameter name by ${!...} From: Tomoki Sekiyama To: Bart Schaefer Cc: "zsh-workers@zsh.org" Content-Type: text/plain; charset=UTF-8 Hi all, Thank you for your comments. > IIRC, in bash, you can also use ${!foo} even with banghist active. We > probably don't want to replicate that feature, but make sure ${\!foo} > works I suppose? Right, I don't think we want to change banghist behavior when it is active. We can avoid banghist by ${\!foo} when it is active. 2015-01-25 16:39 GMT-05:00 Bart Schaefer : > > On Jan 25, 11:38pm, ZyX wrote: > } Subject: Re: [PATCH] Enable further expansion of parameter name by ${!...} > } > } 25.01.2015, 23:25, "Bart Schaefer" : > } > > } > Don't we already have something like this for ksh emulation? Except that > } > it acts like (k) instead of like (P)? Although I can't find this in the > } > documentation anywhere, right at the moment. > } > } I have ksh installed and here `${!VAR}` outputs `VAR` regardless of > } whether $VAR is defined and what type and what value does it have. > > I thought I recalled something about that. So it would appear that > whatever interpretation we're giving it already in ksh mode, is wrong. > > } [Manual page][1] says that it should actually expand to "the name of > } the variable referred to by vname" and says that this will be `VAR` > } unless it is a name reference (I have only tried strings, arrays and > } associative arrays). > } > } [1]: http://unixhelp.ed.ac.uk/CGI/man-cgi?ksh+1 > I have tried some patterns with ksh and bash. ### Variable reference aaa=bbb bbb=ccc # ksh bash zsh(default) zsh(KSH) echo $aaa # bbb bbb bbb bbb echo ${!aaa} # aaa ccc bad substitution bbb ### Assoc typeset -A foo foo[bar]=baz foo["baz"]="qux" baz=piyo # ksh bash zsh(default) zsh(KSH) echo $foo # baz qux echo ${foo[bar]} # baz baz baz baz echo ${foo["bar"]} # baz baz echo ${foo[baz]} # qux qux echo ${foo["baz"]} # qux qux qux qux echo ${!foo[bar]} # foo[bar] piyo bad substitution bar echo ${!foo["bar"]} # foo[bar] piyo bad substitution echo ${!foo[@]} # bar baz bar baz bad substitution "baz" bar It seems that ${!...} in KSH emulation mode of zsh is only useful for the case of "${!foo[@]}", which is substituted with the list of keys of the assoc, that has the same meaning also in bash. (Although zsh regards baz and "baz", or even 'baz' as different keys...) According to this, introducing bash-like behaviors instead of "bad substitution" error will not hurt zsh even in ksh emulation mode. Any comments are appreciated. Thanks, Tomoki