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

Re: array to braced list conversion ?

> Is there a simple possibility to convert an array
> to a brace delimited list?
> E.g.
> set +A LIST a b c
> how can I get the analog of
> ls /usr/local/bin/{a,b,c}
> using LIST ?

The answer to the second question isn't the same as the answer to the
first.  The answer to the second is

ls /usr/local/bin/${^LIST}

which turns on RC_EXPAND_PARAM for the word being evaluated.

If you want a real brace delimited list for some reason, you can do
something like:

eval ls /usr/local/bin/\{${(qj.,.)LIST}\}

The stuff at the end produces the braced expression you want by joining the
array with commas, `(j.,.)'.  The extra (q) adds quotes so that
metacharacters inside $LIST will not be treated specially when the eval
takes place.  The eval is necessary to get the braced expression to be
evaluated as such instead of as literal text.  If there's a way of doing it
without the eval, it doesn't occur to me at the moment.  But that's
probably not what you need anyway.

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070

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