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

Re: expanding nameref target?



On Tue, Feb 21, 2023 at 7:59 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Feb 21, 2023 at 5:08 AM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> >
> > Is there a way to expand a nameref to its target parameter without
> > removing the nameref attribute with +n first?
>
> Not yet.  Still working on that.

So ... opinions solicited before I send a patch.

In ksh emulation (and history disabled), I have this working:

% typeset -n foo=bar
% echo ${!foo}
bar

However, that's pretty clumsy because of history expansion, so I'm
proposing the following for zsh native mode:

% typeset -n foo=bar
% echo ${(?)foo}
bar

As an extension (more by accident than by design but possibly useful):

% echo ${(?)options}
zsh/parameter

This only works for autoloaded parameters that are not yet loaded.

For similarity with ksh mode, ${(!)foo} is a synonym for (?), but that
means we can't use (!) for anything else.  Is that a problem?

I've also made (?) [or (!)] mutually exclusive with (k) and (v).

Thoughts?




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