Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Enable further expansion of parameter name by ${!...}



25.01.2015, 23:25, "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>:
> On Jan 25,  4:15am, Tomoki Sekiyama wrote:
> } Subject: [PATCH] Enable further expansion of parameter name by ${!...}
> }
> } With this change, ${!...} will enable further expansion of parameter name,
> } which is equivalent to (P) expansion flag. This will enable zsh to run some
> } scripts using variable references for bash.
>
> 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. [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'm not going to commit this without some more discussion, though, because
> it seems a bit iffy to have exactly the same syntax mean two such very
> different things.  At the very least perhaps both branches should depend
> on emulation modes rather than having the bash behavior become a default.
>
> diff --git a/Src/subst.c b/Src/subst.c
> index a2bb648..882e62c 100644
> --- a/Src/subst.c
> +++ b/Src/subst.c
> @@ -1734,8 +1734,11 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
>           * doesn't have parameter flags it might be neater to
>           * handle this with the ^, =, ~ stuff, below.
>           */
> - if ((c = *s) == '!' && s[1] != Outbrace && EMULATION(EMULATE_KSH)) {
> -    hkeys = SCANPM_WANTKEYS;
> + if ((c = *s) == '!' && s[1] != Outbrace) {
> +    if (EMULATION(EMULATE_KSH))
> + hkeys = SCANPM_WANTKEYS;
> +    else /* emulate bash equivalent to our (P) */
> + aspar = 1;
>              s++;
>          } else if (c == '(' || c == Inpar) {
>              char *t, sav;



Messages sorted by: Reverse Date, Date, Thread, Author