From: Peter Stephenson <Peter.Stephenson@csr.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Expand array into multiple elements per item?
Date: Tue, 13 Sep 2011 09:57:07 +0100 [thread overview]
Message-ID: <20110913095707.28e2d2d1@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <alpine.LNX.2.01.1109130337270.10525@hp.internal>
On Tue, 13 Sep 2011 04:15:50 -0400
"Benjamin R. Haskell" <zsh@benizi.com> 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@csr.com> 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
next prev parent reply other threads:[~2011-09-13 8:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-13 8:15 Benjamin R. Haskell
2011-09-13 8:36 ` Anthony Charles
2011-09-13 8:52 ` Benjamin R. Haskell
2011-09-15 18:07 ` Oliver Kiddle
2011-09-13 8:57 ` Peter Stephenson [this message]
2011-09-13 10:19 ` Mikael Magnusson
2011-09-13 17:32 ` Benjamin R. Haskell
2011-09-13 17:21 ` Benjamin R. Haskell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110913095707.28e2d2d1@pwslap01u.europe.root.pri \
--to=peter.stephenson@csr.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).