From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29007 invoked by alias); 26 Jan 2015 20:51:34 -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: 34406 Received: (qmail 1963 invoked from network); 26 Jan 2015 20:51:30 -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,T_FSL_HELO_BARE_IP_2 autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1422305085; bh=3fXGoxQJPvEEt5HrnziOSeWABoWvFGvuB4ol3dYqn8M=; h=From:To:Cc:In-Reply-To:References:Subject:Date; b=FxRNGycOwV0TlvUU6ofrPdYqBLFKddP9+1ESSmgTK1EiUTO7aWRETD3yRQglUMfLM CDmLrP9LSlYsi3mu2tsZN2Dw40KcbciBNDMsFpvqgMAQ6vW9ylH8ha5+79/OwvbLaR fsjXEOYGlUhwgpbtUyT9s09HSHnd3aCrvnNu4nxE= From: ZyX To: Tomoki Sekiyama , Bart Schaefer Cc: "zsh-workers@zsh.org" In-Reply-To: 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> Subject: Re: [PATCH] Enable further expansion of parameter name by ${!...} MIME-Version: 1.0 Message-Id: <9318701422305084@web24h.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 26 Jan 2015 23:44:44 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r 26.01.2015, 23:01, "Tomoki Sekiyama" : > 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...) Quote removal is not done in subscripts. In bash you may have `baz`, `'baz'` and `"baz"` and due to quote removal it computes to just `baz`. This is explicitly mentioned in the seventh paragraph of Subscript Parsing subsection of ARRAY PARAMETERS section of `man zshparam`. > > 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