Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
(z) expansion flag do not always return an array
- X-seq: zsh-users 27382
- From: Vincent Bernat <bernat@xxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: (z) expansion flag do not always return an array
- Date: Mon, 29 Nov 2021 16:31:43 +0100
- Archived-at: <https://zsh.org/users/27382>
- List-id: <zsh-users.zsh.org>
Hey!
The (z) expansion flag is documented to return an array, but this is not
the case if we have only one word:
16:24 ❱ print -l ${${(z)${:-word1}}[1]}
w
16:24 ❱ print -l ${${(z)${:-word1 word2}}[1]}
word1
This can be worked around with A:
16:29 ❱ print -l ${${(Az)${:-word1}}[1]}
word1
16:29 ❱ print -l ${${(Az)${:-word1 word2}}[1]}
word1
But older versions of Zsh does not have that. Is there another way? Is
there an easy way to know if something is an array or a string? I am
using subscripting for that but maybe there are better ways.
--
Don't over-comment.
- The Elements of Programming Style (Kernighan & Plauger)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author