Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Help in understanding rules of parameter expansion



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