From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5914 invoked from network); 4 Sep 2006 18:24:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO,UNPARSEABLE_RELAY autolearn=ham version=3.1.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 Sep 2006 18:24:49 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 52534 invoked from network); 4 Sep 2006 18:24:42 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 Sep 2006 18:24:42 -0000 Received: (qmail 14936 invoked by alias); 4 Sep 2006 18:24:33 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10675 Received: (qmail 14927 invoked from network); 4 Sep 2006 18:24:32 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 4 Sep 2006 18:24:32 -0000 Received: (qmail 50992 invoked from network); 4 Sep 2006 18:24:32 -0000 Received: from vms042pub.verizon.net (206.46.252.42) by a.mx.sunsite.dk with SMTP; 4 Sep 2006 18:24:31 -0000 Received: from torch.brasslantern.com ([71.116.118.106]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0J5200HIOZ46TDJF@vms042.mailsrvcs.net> for zsh-users@sunsite.dk; Mon, 04 Sep 2006 13:24:07 -0500 (CDT) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id k84IO55Y009162 for ; Mon, 04 Sep 2006 11:24:05 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id k84IO5SZ009161 for zsh-users@sunsite.dk; Mon, 04 Sep 2006 11:24:05 -0700 Date: Mon, 04 Sep 2006 11:24:05 -0700 From: Bart Schaefer Subject: Re: Solved, but now a new twist (was: Double Evaluation Question (not in FAQ)) In-reply-to: To: "zsh-users Mailinglist" Message-id: <060904112405.ZM9160@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: Comments: In reply to "Com MN PG P E B Consultant 3" "Solved, but now a new twist (was: Double Evaluation Question (not in FAQ))" (Sep 4, 10:43am) On Sep 4, 10:43am, Com MN PG P E B Consultant 3 wrote: } } That is, if I have an assignment } } x='~linus ~steve' } } Is there also a simple solution, which expands $x to the home } directories of linus and steve, with spacing preserved? No. Tildes are only expanded at the beginnings of words, so you have to split the string (thus discarding the spacing, if you don't take special care) before the home directories can be substituted. There's a complicated solution: setopt extendedglob print -r ${(j//)${(s/|/)~${x/(#b)( ##)/|$match|}}} The /(#b)( ##)/ matches a string of one or more spaces, which is then replaced with itself ($match) surrounded by "|" (anything not found in the strings on either side would work). That's then split (s/|/) on vertical bars to make an array of three words, which are made eligible for expansion by the tilde that appears between the closing paren and the start of the inner expansion. Finally this is rejoined into a single string (j//) without adding any additional spaces between the array elements. I'm actually a little surprised that this works -- I would have guessed that joining with (j//) took place before tilde expansion. But it seems to work as far back as backreferences (#b) do, so I guess it's safe to assume it'll keep working. (PWS, does something need to be added to the "Rules" section under "Parameter Expansion"?)