Skip to contentSkip to conversation

Adding to the PATH but not if already in $PATH

DISCUSSION Dog Walker 2 participants 4 messages Feb 26, 2005

lore
Share & tools
lore

Dog Walker

author
#0 lore raw

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#1 lore raw
Quoted 6 lines · you

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:

Quoted 7 lines

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?

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.

Quoted 5 lines

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

Signature · 2 lines
----------------------------------------
--EB
Quoted 4 lines

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-December 08,2000

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

author
#2 lore raw
Quoted 6 lines · Eric Bambach
Quoted 4 lines · you

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.

[...]

Quoted 10 lines

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.

#3 lore raw
Quoted 10 lines · you
Quoted 4 lines · Eric Bambach
Quoted 3 lines · you

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.

[...]

Quoted 2 lines

sed and grep can help.

Quoted 8 lines
Quoted 8 lines

echo $PATH | grep 'SOMEPATH'
if [ $? == 0 ];then
export PATH
else
PATH=NEWPATH
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 pseudocode. I wrote that after I just woke up ;) But I think you got the picture.

Quoted 4 lines

Great!

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

Signature · 2 lines
----------------------------------------
--EB
Quoted 4 lines

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-December 08,2000

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