zsh-workers
 help / color / mirror / code / Atom feed
From: Tomoki Sekiyama <tomoki.sekiyama@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [PATCH] Enable further expansion of parameter name by ${!...}
Date: Mon, 26 Jan 2015 15:00:34 -0500	[thread overview]
Message-ID: <CAM1upfMhyMPCn5urXPUjSTE2K2T3KyaZG6cg2v8vDhWwmHruvw@mail.gmail.com> (raw)
In-Reply-To: <150125133931.ZM32124@torch.brasslantern.com>

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 <schaefer@brasslantern.com>:
>
> On Jan 25, 11:38pm, ZyX wrote:
> } Subject: Re: [PATCH] Enable further expansion of parameter name by ${!...}
> }
> } 25.01.2015, 23:25, "Bart Schaefer" <schaefer@brasslantern.com>:
> } >
> } > 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


  reply	other threads:[~2015-01-26 20:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-25  9:15 Tomoki Sekiyama
2015-01-25 18:14 ` Peter Stephenson
2015-01-25 18:23   ` Mikael Magnusson
2015-01-25 20:24 ` Bart Schaefer
2015-01-25 20:38   ` ZyX
2015-01-25 21:39     ` Bart Schaefer
2015-01-26 20:00       ` Tomoki Sekiyama [this message]
2015-01-26 20:44         ` ZyX
2015-01-27  5:48         ` Bart Schaefer
2015-01-28  3:21           ` Tomoki Sekiyama
2015-01-28 18:41             ` Bart Schaefer
2016-11-11 16:58           ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAM1upfMhyMPCn5urXPUjSTE2K2T3KyaZG6cg2v8vDhWwmHruvw@mail.gmail.com \
    --to=tomoki.sekiyama@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).