Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used this to add to PATH:

APXS2=/usr/local/apache/bin/apxs PATH=$PATH:/usr/local/apache/bin passenger-install-apache2-module

and my PATH now looks like this:

/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:

Now I want to remove this I added. How to do this?

share|improve this question

migrated from stackoverflow.com Feb 24 '11 at 1:15

This question came from our site for professional and enthusiast programmers.

4 Answers 4

The best way might be to simply store a copy of the path before altering it.

PATH_BAK=$PATH
PATH=...
...
PATH=$PATH_BAK
share|improve this answer

Just log out, login again and your PATH will be reset.

share|improve this answer

If you forgot to create a backup you can use the substring removal/replace.

Substring Removal

${string#substring}

Substring Replace

${string/substring/replacement}

Please refer to this link http://www.museum.state.il.us/ismdepts/library/linuxguides/abs-guide/string-manipulation.html

share|improve this answer
    
So what is the answer here ? Your answer does not manipulate the value of PATH - if it needed modifying anyway. –  David Victor Feb 23 '11 at 23:43

Given /usr/local/apache/bin isn't in the '... my PATH now looks like this ...' - what do you think you added ? Assuming you're on bash or ksh - you didn't actually change the path because you didn't export it. So I doubt you need to remove anything.

E.g.

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
$ PATH=$PATH:/foo /bin/ls
aFile
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
$ # PATH did not alter

Versus:

$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
$ export PATH=$PATH:/foo
$ /bin/ls
aFile
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/foo
$ #PATH modified.

So unless you exported the new PATH to the shell you're invoking the command from the PATH did not alter.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.