Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array expansion interacts with brace expansion in the wrong order
- X-seq: zsh-workers 41427
- From: Anders Kaseorg <andersk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Array expansion interacts with brace expansion in the wrong order
- Date: Thu, 13 Jul 2017 21:42:50 -0400 (EDT)
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- In-reply-to: <CAH+w=7bzJx11_LKOtJz0BwVUQM_rU+d2nykybcGhVTMoi6Uj3w@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <alpine.DEB.2.10.1707131831290.28302@mass-toolpike.mit.edu> <CAH+w=7bzJx11_LKOtJz0BwVUQM_rU+d2nykybcGhVTMoi6Uj3w@mail.gmail.com>
On Thu, 13 Jul 2017, Bart Schaefer wrote:
> On Thu, Jul 13, 2017 at 3:45 PM, Anders Kaseorg <andersk@xxxxxxx> wrote:
> > Given a=(1 2 3), I would expect {$^a,4,5,6} to expand to 1 2 3 4 5 6, but
> > it doesn’t. Instead the 4 5 6 is duplicated for every element of $^a
>
> Your expectation is wrong. Brace expansion happens last of all
> (except for globbing), so {$^a,4,5,6} is {1,4,5,6} {2,4,5,6}
> {3,4,5,6}. This is documented.
>
> Even if this happened in the order you expect, the way you've written
> it would have given 1 4 1 5 1 6 2 4 2 5 2 6 3 4 3 5 3 6 because of the
> meaning of $^a.
The documentation for ${^spec} says
“Internally, each such expansion is converted into the equivalent list for
brace expansion. E.g., ${^var} becomes {$var[1],$var[2],...}, and is
processed as described in Brace Expansion below.”
That would seem to support my expectation that {$^a,4,5,6} should become
{{1,2,3},4,5,6}, which expands to 1 2 3 4 5 6.
> What you are after is simply {"$a",4,5,6}.
That produces 4 words ("1 2 3" 4 5 6), and doesn’t generalize (e.g. I
would expect {$^a,4,5,6}{x,y} = {{1,2,3},4,5,6}{x,y} = 1x 1y 2x 2y 3x 3y
4x 4y 5x 5y 6x 6y).
Anders
Messages sorted by:
Reverse Date,
Date,
Thread,
Author