From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23288 invoked by alias); 13 Sep 2011 10:44:21 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16337 Received: (qmail 13287 invoked from network); 13 Sep 2011 10:44:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.212.44 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+rAJZCzT6NrIpAFrxII1X8DNrthzRjLnFzrCmlm7Exo=; b=aFFhiPC/KHdNuDuVm6LPeiEwWwi6PxI1kKWfJHh20SheZw4DFNrkhirwTjEEsBhu0d Q6EUgpjxCINJBhsA/g+q0suw27pj6Q7qKmbRD6PbxzxUlto4B+P5gaNeFp1uuapvglZa c98q7DmyOY6OdEPSTYdqaZ+FUEq+NXLg364GM= MIME-Version: 1.0 In-Reply-To: <20110913095707.28e2d2d1@pwslap01u.europe.root.pri> References: <20110913095707.28e2d2d1@pwslap01u.europe.root.pri> Date: Tue, 13 Sep 2011 12:19:55 +0200 Message-ID: Subject: Re: Expand array into multiple elements per item? From: Mikael Magnusson To: Zsh Users Content-Type: text/plain; charset=UTF-8 On 13 September 2011 10:57, Peter Stephenson wrote: >> 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:) One fun thing you can do is use .(e,'reply=(foo bar baz)',) if you want to use some other globbing flags on your data. It's not applicable for this problem, at least I can't think of a way. I did suggest it on irc once for sorting an array by the basename: 22:39 I want to sort this by basename so that I order the elements in this pair of expansions asciibetically regardless of the directory they're found in. 22:39 (so, for example, if I had A/02_something B/01_something B/03_something, it'd come out as B/01_something A/02_something B/03_something) 22:47 a=( oneglob anotherglob ) 22:47 echo .(e:'reply=($a)':oe,'REPLY=$REPLY:t',) It would be nice to have a similar mechanism for sorting arrays maybe :). Oh wait, I just realized it does work, just do this: % print -l - .(e:'reply=($somelist)':P:-id:) -id a b -id c -id d e Obviously, this does qualify in the 'a bit of a hack' category. (And yes, it does fail if $PWD is chmoded -x, maybe / is a safer bet.) -- Mikael Magnusson