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

fewer forks



I have a couple of shell functions that I use to manipulate my environment and I'm looking to see if these can be done in a more "zsh way", specifically with fewer forks to external programs.

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.   Currently I have functions like:


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
}

but thats a lot of external processes (env, grep, grep, cut, echo) to do something that seems like it should be simple.

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.

Thanks,
Scott




Messages sorted by: Reverse Date, Date, Thread, Author