From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17556 invoked from network); 25 May 2009 17:06:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from new-brage.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.254.104) by ns1.primenet.com.au with SMTP; 25 May 2009 17:06:23 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 89762 invoked from network); 25 May 2009 17:06:13 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 25 May 2009 17:06:13 -0000 Received: (qmail 7687 invoked by alias); 25 May 2009 17:05:55 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 14176 Received: (qmail 7678 invoked from network); 25 May 2009 17:05:55 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 25 May 2009 17:05:55 -0000 Received: from vms173005pub.verizon.net (vms173005pub.verizon.net [206.46.173.5]) by bifrost.dotsrc.org (Postfix) with ESMTP id 88E3480307FB for ; Mon, 25 May 2009 19:05:51 +0200 (CEST) Received: from torch.brasslantern.com ([96.249.201.13]) by vms173005.mailsrvcs.net (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTPA id <0KK7007ZKM5BIEA4@vms173005.mailsrvcs.net> for zsh-users@sunsite.dk; Mon, 25 May 2009 12:05:40 -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 n4PH5YdK015573 for ; Mon, 25 May 2009 10:05:35 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id n4PH5Xvh015572 for zsh-users@sunsite.dk; Mon, 25 May 2009 10:05:33 -0700 From: Bart Schaefer Message-id: <090525100533.ZM15571@torch.brasslantern.com> Date: Mon, 25 May 2009 10:05:33 -0700 In-reply-to: <580cd3b30905250659y3efb6099n98b97c4e104c900f@mail.gmail.com> Comments: In reply to Scott Lipcon "fewer forks" (May 25, 9:59am) References: <580cd3b30905250659y3efb6099n98b97c4e104c900f@mail.gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@sunsite.dk Subject: Re: fewer forks MIME-version: 1.0 Content-type: text/plain; charset=us-ascii X-Virus-Scanned: ClamAV 0.94.2/9390/Mon May 25 14:49:36 2009 on bifrost X-Virus-Status: Clean On May 25, 9:59am, Scott Lipcon wrote: } } 1) look for environment variables matching a pattern. I have a number of } environment variables that all end in ROOT,and I need to add each } $FOOROOT/bin to my path, $FOOROOT/lib to my LD_LIBRARY_PATH, etc. } } function setLDPath { } ld_library_path=( $base_ld_path ) } } for dir in `=env | =grep ROOT | =grep -v 'CVSROOT' | =cut -f1 -d=`; do } ld_library_path=( $(eval "echo \$$dir/lib") $ld_library_path ) } done function setLDPath { zmodload zsh/parameter ld_library_path=() for dir in ${(k)parameters[(I)*ROOT]}; do if [[ $dir != CVSROOT && $parameters[$dir] = *export* ]]; then ld_library_path+=( ${(P)dir}/lib ) fi done ld_library_path+=( $base_ld_path ) } That's not quite identical because it builds by appending in arbitrary order rather than prepending in alphabetical order; if for some reason alphabetical order actually matters, use ${(Ok)parameters[(I)*ROOT]}. } 2) grep for a pattern in a file. In general zsh is not going to do this as well as grep and thus saving the overhead of the fork worth it. In your specific example, though: } The project i work on has a csh script to set some variables } (specifically, the $FOOROOT variables, above. It may very well be possible to define setenv and possibly a few other zsh functions and then simply "source" the csh script. For example I use: setenv () { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } } then I have another grep piped to sed and tr to get (and slightly transform) } the value. Aside: It's almost never necessary to pipe grep to sed, because sed can do the pattern search itself. Depending on what you're doing with sed and tr, you can probably apply the transformation to ${(@)argv[2,$#]} inside the setenv function using zsh parameter manipulations.