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

Re: (z) expansion flag do not always return an array



 ❦ 29 November 2021 11:50 -05, Lawrence Velázquez:

>> The (z) expansion flag is documented to return an array
>
> Is it?  The 5.8 man page does not mention "array" even once.
>
>     z   Split the result of the expansion into words using shell
>         parsing to find the words, i.e. taking into account any
>         quoting in the value.  Comments are not treated specially but
>         as ordinary strings, similar to interactive shells with the
>         INTERACTIVE_COMMENTS option unset (however, see the Z flag
>         below for related options)
>
>         Note that this is done very late, even later than the `(s)'
>         flag.  So to access single words in the result use nested
>         expansions as in `${${(z)foo}[2]}'.  Likewise, to remove the
>         quotes in the resulting words use `${(Q)${(z)foo}}'.

When I read "split", I read "into an array". I must miss something.
Also, it works when there is something to split, but not when there is
only one word.
-- 
Don't use conditional branches as a substitute for a logical expression.
            - The Elements of Programming Style (Kernighan & Plauger)




Messages sorted by: Reverse Date, Date, Thread, Author