Adding to the PATH but not if already in $PATH

Adding to the PATH but not if already in $PATH

am 26.02.2005 19:17:00 von DogWalker

I want to prepend a directory to my PATH in my $HOME/.bashrc and export the
result. But I only want it to happen once: iow, if a directory I want
prepended is already in the PATH, do not prepend it again.

Something like:

if "/home/dw/bin" not in $PATH ; then
PATH=/home/dw:$PATH
export PATH
fi

The questions are: Is this the way one guards against multiple additions in
subshells? Is there a way to check for a substring?

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: Adding to the PATH but not if already in $PATH

am 26.02.2005 20:05:35 von Eric Bambach

On Saturday 26 February 2005 12:17 pm, you wrote:
> I want to prepend a directory to my PATH in my $HOME/.bashrc and expo=
rt the
> result. But I only want it to happen once: iow, if a directory I want
> prepended is already in the PATH, do not prepend it again.
>
> Something like:
>
> if "/home/dw/bin" not in $PATH ; then
> PATH=3D/home/dw:$PATH
> export PATH
> fi
>
> The questions are: Is this the way one guards against multiple additi=
ons in
> subshells? Is there a way to check for a substring?

sed and grep can help.

echo $PATH | grep 'SOMEPATH'
if [ $? == 0 ];then
export PATH
else
PATH=3DNEWPATH
fi

Check the login on that though, shouldnt be too hard.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbi=
e" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs

--=20
----------------------------------------
--EB

> All is fine except that I can reliably "oops" it simply by trying to =
read
> from /proc/apm (e.g. cat /proc/apm).
> oops output and ksymoops-2.3.4 output is attached.
> Is there anything else I can contribute?

The latitude and longtitude of the bios writers current position, and
a ballistic missile.

                --Alan Cox LKML-Decembe=
r 08,2000=20

----------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: Adding to the PATH but not if already in $PATH

am 26.02.2005 20:40:15 von DogWalker

MIME Message
--===============1137088125==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

"Eric Bambach" said:

>On Saturday 26 February 2005 12:17 pm, you wrote:
>> I want to prepend a directory to my PATH in my $HOME/.bashrc and export the
>> result. But I only want it to happen once: iow, if a directory I want
>> prepended is already in the PATH, do not prepend it again.
>>
>

[...]

>sed and grep can help.
>
>echo $PATH | grep 'SOMEPATH'
>if [ $? == 0 ];then
> export PATH
>else
> PATH=NEWPATH
>fi
>
>Check the login on that though, shouldnt be too hard.

Great!

Sorry about the double post: kmail did what I said not what
I meant.

--===============1137088125==--
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Re: Adding to the PATH but not if already in $PATH

am 26.02.2005 21:34:46 von Eric Bambach

On Saturday 26 February 2005 01:40 pm, you wrote:
> "Eric Bambach" said:
> >On Saturday 26 February 2005 12:17 pm, you wrote:
> >> I want to prepend a directory to my PATH in my $HOME/.bashrc and e=
xport
> >> the result. But I only want it to happen once: iow, if a directory=
I
> >> want prepended is already in the PATH, do not prepend it again.
>
> [...]
>
> >sed and grep can help.
> >
> >echo $PATH | grep 'SOMEPATH'
> >if [ $? == 0 ];then
> > export PATH
> >else
> > PATH=3DNEWPATH
> >fi
> >
> >Check the login on that though, shouldnt be too hard.

errr....check the *logic* on that. The syntax is mostly good but treat =
it as=20
pseudocode. I wrote that after I just woke up ;) But I think you got th=
e=20
picture.

> Great!
>
> Sorry about the double post: kmail did what I said not what
> I meant.

--=20
----------------------------------------
--EB

> All is fine except that I can reliably "oops" it simply by trying to =
read
> from /proc/apm (e.g. cat /proc/apm).
> oops output and ksymoops-2.3.4 output is attached.
> Is there anything else I can contribute?

The latitude and longtitude of the bios writers current position, and
a ballistic missile.

                --Alan Cox LKML-Decembe=
r 08,2000=20

----------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs