Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Brace expansion as array literals, bug or feature?
- X-seq: zsh-users 20240
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Brace expansion as array literals, bug or feature?
- Date: Sun, 31 May 2015 07:15:46 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=CBwrhzlt7824z5yF2UbjhnVl5w1dzKuzOZBPfVTcRAo=; b=nw0Lg9QUstbk/iqkYHVavPQYu3rTHst7frZcowmTxWOKQ2q+luI3WkA4Jfsyu5TWes LkLoznVXX+EykTRNTX/jzsiIGBRcPOeN98lmIGVQf0FFuRce5nX9aRDfVvP0uM6RElKk o1w8/GfyS1BUj27OzWR+kfeWcSJ0I+oPFyNFrFcXpeZsKDU2/H6Mecz7e21nYuJ5rmNK 72Lh0wwlSiOa38YVJOkser9fVb7x8w94QOvdSVXXnyGpIP0FNaQ5+T5z8e9DVYjJ7xBr pZD6zlGtD6HZbV77nGLBoCPOSdX5P/Ia0ayk/DdtzCtGeBonMpg/+gbtmC0YUTyjlqix Tjzg==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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