[olug] conditional $PATH

Vincent Raffensberger Vincent.Raffensberger at dtn.com
Thu Aug 4 20:41:22 UTC 2005


"After" is just an optional argument to make it add the path to the end
rather than the beginning of the variable.

This would add it to the end:
pathmunge /some/path after

BTW, this function is straight from a redhat's /etc/profile script.
It's handy and helps keep your PATH variable from having many duplicates
in it.

-----Original Message-----
From: olug-bounces at olug.org [mailto:olug-bounces at olug.org] On Behalf Of
Tim & Alethea Larson
Sent: Thursday, August 04, 2005 3:29 PM
To: Omaha Linux User Group
Subject: Re: [olug] conditional $PATH

Vincent Raffensberger wrote:
> Something like this would do the job in ~/.*profile:
> 
> pathmunge () {
>         if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
>            if [ "$2" = "after" ] ; then
>               PATH=$PATH:$1
>            else
>               PATH=$1:$PATH
>            fi
>         fi
> }

I see what this is trying to do, but I don't follow how it actually does
it.  I.e., where does "after" come from?

> if [ `id -g` = 1000 ]; then
>         pathmunge /some/path
>         pathmunge /some/other/path
> fi

Cool, this is what I needed.  I will probably use the -Gn flag instead
though.

Thanks,
Tim
--
Tim & Alethea
christtrek.org
_______________________________________________
OLUG mailing list
OLUG at olug.org
http://lists.olug.org/mailman/listinfo/olug



More information about the OLUG mailing list