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

Re: can I control brace expansion's "sort"/"display" order?



On Aug 31,  2:34am, Eric De Mund wrote:
}
} Can I control brace expansion's "sort" or "display" order?

They're expanded lexically left to right, so the only way to affect
this is to perform the "multiplication" yourself.

In addition to the for-loop solution previously posted, you can do this
with array parameter expansion:

a=( white black )
b=( bird fish )
c=( {21..24} )
d=( ${^a}'${^b}' )
e=( '${(e)^d}'${^c} )

print -l ${(e)e}

The trick is at each step to quote the expansion of the thing you want
to iterate "fastest", and pair it with the thing you want to iterate
"second fastest".  If there's been such a quote at the previous step,
include (e) in its expansion at the next step.  Then expand the whole
thing with (e) to explode the quoted expansions in the correct order.

You can compress this down a little:

a=( bird fish )
b=( {white,black}'${^a}' )
c=( '${(e)^b}'{21..24} )

print -l ${(e)c}

However, as soon as you need the quoting you need a parameter, because
brace expansion isn't repeated during (e) expansion.

-- 



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