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

brace expansion inconsistency



Matt Armstrong wrote:
> 
> Is there a simple way to turn an array (a b c) into (a "" b "" c "")?
> Then I could assign _p4_cmds in one statement and dump the loop.
> 

I would have thought that _p4_cmds=( {$a,} ) would do the job but
it doesn't. On closer inspection, it seems that {,$a} does expand
in the way I would expect with alternate array elements and empty
strings.

In bash {x,} expands to just 'x'. ksh 93 expands it to two
words - 'x' and an empty word. zsh is different for
{x,} and {,x}. I'd argue that ksh93 is right.

Any thoughts?

And, Matt, for now, you could use this:
  a=( {,$a} )
  typeset -A _p4_cmds
  _p4_cmds=( "${(@)a[2,-1]}" '' )

Oliver

This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information on a pro-active anti-virus service working around the clock, around the globe visit http://www.messagelabs.com/



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