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

Re: joining array elements



Wataru Kagawa wrote:
> I think my example was unclear (Sorry).  Basically, I wanted an  
> output that looks like,
> 
> David
> Matt
> Bob[return]Sara[return]Tim
> 
> I can get it with,
> foo=$( printf '%s\n' David Matt ${(j:[return]:)usernames} )
> with the 'globsubst' option turned off.  However, I was trying to  
> incorporate your tip, because I wanted to keep that option turned on.
> 
> foo=$( printf '%s\n' David Matt ${(j:[return]:)~~usernames} )
> gives me no output (with the 'nullglob' option set).

Are you sure that it's not the nullglob option being applied to the
expansion of $foo?
Try

  print -r "$foo"

You can also do

  usernames=(Bob Sara Tim)
  usernames2=(David Matt ${(j.[return].)~~usernames})
  foo=${(F)~~usernames2}

Come to think of it, simply quoting the values is a bit neater than the
the ~~ flag:

  usernames=(Bob Sara Tim)
  usernames2=(David Matt "${(j.[return].)usernames}")
  foo="${(F)usernames2}"

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


Your mail client is unable to display the latest news from CSR. To access our news copy this link into a web browser:  http://www.csr.com/email_sig.html



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