Re: Zsh's and ksh's bang (!) expansion flags have different meanings
"Mark J. Reed" <[email protected]> Mon, 20 Jul 2026 11:32:47 -0400
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAA=-s3z1ShDuw+JnGg5YHDHmEdR8T5pfW_PBdrnCX9CGYL=G4A@mail.gmail.com> |
--0000000000000eb55d06570c9f7e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
>
> I guess this would conflict with nameref-to-assoc, which currently does
> what I would expect. (Unless I'm missing something).
> % typeset -n n=3Da
> % echo ${n}
> 1 2
> % echo ${(k)n}
> a b
% typeset -A a=3D( a 1 b 2 )
Indeed. For reference, ksh;
$ typeset -A foo=3D([a]=3D1 [b]=3D2)
$ typeset -n bar=3Dfoo
$ echo ${!bar}
foo
$ echo "${!bar[@]}"
a b
Given Zsh's default unsubscripted-array expansion behavior, it seems like
it would be hard to maintain the distinction between "what does this
nameref point to" and "what are that thing's keys" if those semantics were
combined in a single flag.
On Sun, Jul 19, 2026 at 11:49=E2=80=AFPM Mikael Magnusson <[email protected]=
m> wrote:
> On Sun, Jul 19, 2026 at 11:53=E2=80=AFPM Bart Schaefer
> <[email protected]> wrote:
> >
> > On Sun, Jul 19, 2026 at 10:24=E2=80=AFAM Philippe Altherr
> > <[email protected]> wrote:
> > >
> > > On Sun, Jul 19, 2026 at 6:36=E2=80=AFPM Bart Schaefer <
> [email protected]> wrote:
> > >>
> > >> You're not noticing anything new, or rather the only thing new that
> you're noticing is that the (!) flag exists at all.
> > >
> > > I'm fully aware that the (!) flag is a part of named references, so
> not already present in any released version of Zsh.
> >
> > Well, yes. The (sorry, unstated) point was that everything you said
> > about (k) is long-standing and (hopefully?) derivable from
> > documentation or FAQ.
> >
> > However, if someone wants to convert those tables of differences into
> > a format that could be included in either the FAQ or the "Other
> > Differences" section of the zsh/ksh93 module documentation, it would
> > probably be quite useful.
> >
> > >>> In ksh, the (!) flag can be used to list the keys of arrays and
> associative arrays. In that regard, it's closer to Zsh's (k) flag than
> Zsh's (!) flag
> >
> > The (k) flag was originally intended to mimic ksh's ! name prefix (due
> > to ! colliding with history). The character "k" was chosen as a
> > mnemonic for "like (k)sh". I suppose, rather than introduce (!), I
> > could have extended (k) for the named reference behavior, to preserve
> > that similarity. Could still try that if it seems a good idea.
>
> I guess this would conflict with nameref-to-assoc, which currently
> does what I would expect. (Unless I'm missing something).
> % typeset -A a=3D( a 1 b 2 )
> % typeset -n n=3Da
> % echo ${n}
> 1 2
> % echo ${(k)n}
> a b
>
> --
> Mikael Magnusson
>
>
--=20
Mark J. Reed <[email protected]>
--0000000000000eb55d06570c9f7e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px =
0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I guess =
this would conflict with nameref-to-assoc, which currently does what I woul=
d expect. (Unless I'm missing something).<br><font face=3D"monospace">%=
typeset -n n=3Da</font><br><font face=3D"monospace">% echo ${n}</font><br>=
<font face=3D"monospace">1 2</font><br><font face=3D"monospace">% echo ${(k=
)n}</font><br><font face=3D"monospace">a b</font></blockquote><div dir=3D"l=
tr"><blockquote style=3D"margin:0px 0px 0px 40px;border-width:medium;border=
-style:none;border-color:currentcolor;padding:0px"><font face=3D"monospace"=
>% typeset -A a=3D( a 1 b 2 )<br></font></blockquote></div><div><br></div>I=
ndeed. For reference, ksh;<blockquote style=3D"margin:0 0 0 40px;border:non=
e;padding:0px"><div><font face=3D"monospace">$ typeset -A foo=3D([a]=3D1 [b=
]=3D2)</font></div><div><font face=3D"monospace">$ typeset -n bar=3Dfoo</fo=
nt></div><div><font face=3D"monospace">$ echo ${!bar}</font></div><div><fon=
t face=3D"monospace">foo</font></div><div><font face=3D"monospace">$ echo &=
quot;${!bar[@]}"</font></div><div><font face=3D"monospace">a b</font><=
/div><div><font face=3D"monospace"><br></font></div></blockquote><div><font=
face=3D"arial, sans-serif">Given Zsh's default unsubscripted-array exp=
ansion behavior, it seems like it would be hard to maintain the distinction=
between "what does this nameref point to" and "what are tha=
t thing's keys" if those semantics were combined in a single flag.=
</font></div><div><br></div><div><div><div class=3D"gmail_quote gmail_quote=
_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jul 19, 2026 at 1=
1:49=E2=80=AFPM Mikael Magnusson <<a href=3D"mailto:[email protected]">m=
[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex">On Sun, Jul 19, 2026 at 11:53=E2=80=AFPM Bart Schaefer<br>
<<a href=3D"mailto:[email protected]" target=3D"_blank">schaefer=
@brasslantern.com</a>> wrote:<br>
><br>
> On Sun, Jul 19, 2026 at 10:24=E2=80=AFAM Philippe Altherr<br>
> <<a href=3D"mailto:[email protected]" target=3D"_blank">ph=
[email protected]</a>> wrote:<br>
> ><br>
> > On Sun, Jul 19, 2026 at 6:36=E2=80=AFPM Bart Schaefer <<a href=
=3D"mailto:[email protected]" target=3D"_blank">schaefer@brasslante=
rn.com</a>> wrote:<br>
> >><br>
> >> You're not noticing anything new, or rather the only thin=
g new that you're noticing is that the (!) flag exists at all.<br>
> ><br>
> > I'm fully aware that the (!) flag is a part of named referenc=
es, so not already present in any released version of Zsh.<br>
><br>
> Well, yes.=C2=A0 The (sorry, unstated) point was that everything you s=
aid<br>
> about (k) is long-standing and (hopefully?) derivable from<br>
> documentation or FAQ.<br>
><br>
> However, if someone wants to convert those tables of differences into<=
br>
> a format that could be included in either the FAQ or the "Other<b=
r>
> Differences" section of the zsh/ksh93 module documentation, it wo=
uld<br>
> probably be quite useful.<br>
><br>
> >>> In ksh, the (!) flag can be used to list the keys of arra=
ys and associative arrays. In that regard, it's closer to Zsh's (k)=
flag than Zsh's (!) flag<br>
><br>
> The (k) flag was originally intended to mimic ksh's ! name prefix =
(due<br>
> to ! colliding with history).=C2=A0 The character "k" was ch=
osen as a<br>
> mnemonic for "like (k)sh".=C2=A0 I suppose, rather than intr=
oduce (!), I<br>
> could have extended (k) for the named reference behavior, to preserve<=
br>
> that similarity.=C2=A0 Could still try that if it seems a good idea.<b=
r>
<br>
I guess this would conflict with nameref-to-assoc, which currently<br>
does what I would expect. (Unless I'm missing something).<br>
% typeset -A a=3D( a 1 b 2 )<br>
% typeset -n n=3Da<br>
% echo ${n}<br>
1 2<br>
% echo ${(k)n}<br>
a b<br>
<br>
-- <br>
Mikael Magnusson<br>
<br>
</blockquote></div><div><br clear=3D"all"></div><div><br></div><span class=
=3D"gmail_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_s=
ignature">Mark J. Reed <<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>><br></div></div></div></div>
--0000000000000eb55d06570c9f7e--