Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Help in understanding rules of parameter expansion
- X-seq: zsh-users 30054
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Cc: Dhruv Singla <dvsingla.28@xxxxxxxxx>
- Subject: Re: Help in understanding rules of parameter expansion
- Date: Thu, 22 Aug 2024 18:32:47 -0400
- Archived-at: <https://zsh.org/users/30054>
- In-reply-to: <CAN=4vMp=nvWa-rbW_OR3VDuoGnGT6k-33B+Jyd+f_R08Yt+itQ@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>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author