Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Expand array into multiple elements per item?
- X-seq: zsh-users 16335
- From: Peter Stephenson <Peter.Stephenson@xxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Expand array into multiple elements per item?
- Date: Tue, 13 Sep 2011 09:57:07 +0100
- In-reply-to: <alpine.LNX.2.01.1109130337270.10525@hp.internal>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Cambridge Silicon Radio
- References: <alpine.LNX.2.01.1109130337270.10525@hp.internal>
On Tue, 13 Sep 2011 04:15:50 -0400
"Benjamin R. Haskell" <zsh@xxxxxxxxxx> wrote:
> Three questions:
>
> 1. How can I easily take:
>
> somelist=( 'a b' c 'd e' )
>
> and get back:
>
> anotherlist=( -id 'a b' -id c -id 'd e' )
anotherlist=({-id,${^somelist}})
> 2. ...relatedly, I'm confused by the following:
>
> $ somelist=( 'a b' c 'd e' )
> $ print -l - $somelist
> a b
> c
> d e
> (i) $ print -l - $^somelist(e:'reply=( -id $REPLY )':)
> zsh: no matches found: a b(e:reply=( -id $REPLY ):)
> (ii) $ print -l - $^somelist(Ne:'reply=( -id $REPLY )':)
> (...nothing printed...)
> $
>
> Why does neither (i) nor (ii) work?
The main problem is that globbing flags rely on globbing; if there's no
matching file, it doesn't work. You'd probably want "oN" in the
globbing flags to turn off sorting if you did have files.
> 3. I thought I recalled a relatively recent addition to parameter
> expansion flags for just this use-case. But I can't seem to find the
> flag in zsh-4.3.12 patchlevel 1.5346. Still interested in the answer to
> the rest, regardless.
You might be thinking of the globbing flag, P. If you did have files,
*(P:-id:) would have done what you wanted. But you don't. The actual
effect is a bit bizarre (turning off nomatch):
-id
a b(P:-id:)
-id
c(P:-id:)
-id
d e(P:-id:)
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog
Messages sorted by:
Reverse Date,
Date,
Thread,
Author