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

Re: Array expansion interacts with brace expansion in the wrong order



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.

What you are after is simply {"$a",4,5,6}.



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