Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Help in understanding rules of parameter expansion
- X-seq: zsh-users 30055
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: zsh-users@xxxxxxx
- Subject: Re: Help in understanding rules of parameter expansion
- Date: Fri, 23 Aug 2024 21:11:14 +0200
- Archived-at: <https://zsh.org/users/30055>
- In-reply-to: <CAH+w=7YhFE-RyQhXt_nShkQu8Zs4XzC05mevwUPMjRMgjsU05g@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CACpv_eKY2eOaq6b-nJkXEB2YXar14gMw1aWsb-1y_tDTUzo08A@mail.gmail.com> <CAN=4vMp=nvWa-rbW_OR3VDuoGnGT6k-33B+Jyd+f_R08Yt+itQ@mail.gmail.com> <CAH+w=7YhFE-RyQhXt_nShkQu8Zs4XzC05mevwUPMjRMgjsU05g@mail.gmail.com>
On Fri, Aug 23, 2024 at 12:33 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Aug 22, 2024 at 3:37 AM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> > % foo=AxB
> > % bar=${(s.x.)foo}
> > % baz=${${(s.x.)foo}}
> > % typeset -p bar baz
> > typeset bar=AxB
> > typeset baz='A B'
> >
> > I might be missing something but I expect $bar to be the same as $baz.
>
> Hrm. ${(s.x.)foo} produces an array result. bar=${(s.x.)foo} is a
> scalar assignment. There's no implicit join, because (per the
> "Rules") all joining takes place before splitting. So the result of
> this assignment is unspecified; I suppose it could have generated an
> "inconsistent type for assignment" error, but the internals just throw
> away the array value and use the scalar value.
>
> Conversely ${${(s.x.)foo}} has an implicit join step after the split
> because of the inside-out ordering of nested expansions.
I was thinking something along these lines too, but shouldn't it at
least act the same as double quoted "${(s.x)foo}" (not in an
assignment)?
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author