Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: fewer forks



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