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

Brace expansion as array literals, bug or feature?



You can do this
% print -rl - ${(Oa):-{a,b,c}}
c
b
a

But not this
% print -rl - "${(Oa):-{a,b,c}}"
{a,b,c}

I can't really recall seeing any statement in the manpage that either
of these ought to work. The first one does not simply expand to three
parameter substitutions; if it did, the order would not be reversed
over the whole array by (Oa).

This is clearly a ridiculous workaround,
% print -rl - ${${(A)reply::={a,b,,c}}+} "${${(@Oa)reply}}"
c  b a

Another nice thing is you don't need to quote spaces in this form :)
% print -l {a,b b,c}
zsh: parse error near `}'
% print -l ${:-{a,b b,c}}
a
b b
c

Before discovering this, I usually did something like ${(s:,:):-a,b,c}
but that feels somehow more hacky. Is there another way to do an array
literal that I'm not thinking of?

-- 
Mikael Magnusson



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