Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expanding nameref target?
- X-seq: zsh-workers 51487
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: expanding nameref target?
- Date: Mon, 27 Feb 2023 21:00:49 -0800
- Archived-at: <https://zsh.org/workers/51487>
- In-reply-to: <CAH+w=7bzkkKAg+TF9itdSeffk4VjfJWQnBgXonLn_cRA=ETrnQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHYJk3TgMpb0Z3cmLhZ-EQ5p8o_q9G7KE-mF1UAGguoOY=cQeQ@mail.gmail.com> <CAH+w=7bzkkKAg+TF9itdSeffk4VjfJWQnBgXonLn_cRA=ETrnQ@mail.gmail.com>
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