Re: Zsh's and ksh's bang (!) expansion flags have different meanings

Bart Schaefer <[email protected]> Sun, 19 Jul 2026 09:44:44 -0700
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAH+w=7b-ywDG_wWJk_2D_n6zT9KS1YQ4UO7xv-axSO6deqQE3w@mail.gmail.com>
--00000000000076955d0656f98262
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 19, 2026 at 8:51=E2=80=AFAM Philippe Altherr <philippe.altherr@=
gmail.com>
wrote:

> Another difference is that in Zsh the (k) flag doesn't work for array
> ranges ("${(k)arr[*]}" returns "aa bb cc"), while in ksh it does
> ("${!arr[*]}" returns "0 1 2"). To me, this looks like something that oug=
ht
> to be changed in Zsh.
>

This is very difficult because zsh always passes parameter replacements
around by value rather than by reference.  By the time the parameter
expansion stack unwinds to the place where it might want keys, the keys are
gone and all that's left is an array of values.

--00000000000076955d0656f98262
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">On Sun, Jul 19, 2026 at 8:51=E2=80=AFAM P=
hilippe Altherr &lt;<a href=3D"mailto:[email protected]">philippe.=
[email protected]</a>&gt; wrote:</div><div class=3D"gmail_quote gmail_quote=
_container"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"l=
tr"><div>Another difference is that in Zsh the (k) flag doesn&#39;t work fo=
r array ranges (&quot;${(k)arr[*]}&quot; returns &quot;aa bb cc&quot;), whi=
le in ksh it does (&quot;${!arr[*]}&quot; returns &quot;0 1 2&quot;). To me=
, this looks like something that ought to be changed in Zsh.</div></div></b=
lockquote><div><br></div><div>This is very difficult because zsh always pas=
ses parameter replacements around by value rather than by reference.=C2=A0 =
By the time the parameter expansion stack unwinds to the place where it mig=
ht want keys, the keys are gone and all that&#39;s left is an array of valu=
es.</div></div></div>

--00000000000076955d0656f98262--