Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: fewer forks
- X-seq: zsh-users 14175
- From: Daniel Friesel <derf@xxxxxxxxxxxxxxxxxxxxxxx>
- To: Scott Lipcon <slipcon@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Subject: Re: fewer forks
- Date: Mon, 25 May 2009 18:56:40 +0200
- In-reply-to: <580cd3b30905250659y3efb6099n98b97c4e104c900f@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <580cd3b30905250659y3efb6099n98b97c4e104c900f@xxxxxxxxxxxxxx>
On Mon, May 25, 2009 at 09:59:56AM -0400, 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.
You could iterate over ${(k)parameters} and check for [[ $dir == *ROOT &&
$dir != CVSROOT ]].
> 2) grep for a pattern in a file. The project i work on has a csh script to
> set some variables (specifically, the $FOOROOT variables, above. Currently
> I'm doing:
>
> for root in `=grep '^setenv .*ROOT ' $REQS | =cut -f2 -d' '`; do
> ...
> done
>
> which pulls the name of the environment variable out of the file ($REQS) and
> then I have another grep piped to sed and tr to get (and slightly transform)
> the value.
>
grep should be the best choice there. You can of course use read
instead and then check each line, but I guess that would be a lot
slower.
Same goes for grep | sed | tr - When it comes to operating on streams,
I found these to be far more efficient than the zsh builtins (which
usually operate on single values and need to be wrapped into read or
similar).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author