LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to remove directory from $PATH (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-directory-from-%24path-483463/)

infraredgirl 09-14-2006 10:48 AM

How to remove directory from $PATH
 
I accidentally added a wrong directory to $PATH. How do I remove it?

olaola 09-14-2006 11:03 AM

How did you added the directory?

infraredgirl 09-14-2006 11:06 AM

Like this:
Code:

export PATH=${PATH}:/blah/wrongdir

olaola 09-14-2006 11:16 AM

if you reboot your machine (or maybe simply logout) the PATH will be read from the ~/.bash_profile file, so restored as previously

infraredgirl 09-14-2006 05:01 PM

Yes you are right.
Thank you.

ntubski 09-14-2006 09:36 PM

Next time you can set PATH to the empty string then rerun /etc/profile and ~/.bash_profile like this:
Code:

PATH=""
source /etc/profile
source ~/.bash_profile

No reboot/logout necessary :)

Edit: I thought of a better way
Code:

PATH=$(echo $PATH |sed 's/\/blah\/wrongdir//')

Paris Heng 03-27-2009 05:31 AM

Quote:

Originally Posted by olaola (Post 2422717)
if you reboot your machine (or maybe simply logout) the PATH will be read from the ~/.bash_profile file, so restored as previously

I also having the problems today, why the alteration never permanently store in the kernel? I wonder, export PATH=${PATH}:/blah/wrongdir, never store permanently?

i92guboj 03-27-2009 05:52 AM

Quote:

Originally Posted by Paris Heng (Post 3489362)
I also having the problems today, why the alteration never permanently store in the kernel? I wonder, export PATH=${PATH}:/blah/wrongdir, never store permanently?

I don't know what do you mean but environment variables have nothing to do with the kernel, not even with linux. They are parsed by the shell and have meaning only while you are inside a shell.

~/.bashrc and ~/.bash_profile just happen to be two of the the initialization files for bash, which is just one of the available shells. If you were using tcsh, zsh or ksh then they would be different.

It's the way that shells work, if you want something to be permanent you have to put it on their initialization files, bash doesn't save anything automatically, and I can't think of any other shell that does so.

About "export", well, it doesn't export anything in that sense that you probably though. "export" is just a keyword that tells bash that that variable should be marked as exportable, so it will be available for child processes in case they need it. If the variable is not exported, most child processes will not be able to see a variable that you set in the current shell. It doesn't save anything and it doesn't "export" anything to the config files either, if that's what you thought.

vlademir 03-27-2009 05:53 AM

To remove that directory without rewriting the whole PATH, if i remember this will be the command :

Quote:

export PATH=`echo $PATH | sed -e 's/:\/blah\/wrongdi$//'`
Hope will help

i92guboj 03-27-2009 06:17 AM

In bash a builtin can take care of that as well:

Code:

PATH="${PATH/\/path\/to\/remove/}"

Paris Heng 03-27-2009 08:24 AM

Quote:

Originally Posted by i92guboj (Post 3489385)
I don't know what do you mean but environment variables have nothing to do with the kernel, not even with linux. They are parsed by the shell and have meaning only while you are inside a shell.

~/.bashrc and ~/.bash_profile just happen to be two of the the initialization files for bash, which is just one of the available shells. If you were using tcsh, zsh or ksh then they would be different.

It's the way that shells work, if you want something to be permanent you have to put it on their initialization files, bash doesn't save anything automatically, and I can't think of any other shell that does so.

About "export", well, it doesn't export anything in that sense that you probably though. "export" is just a keyword that tells bash that that variable should be marked as exportable, so it will be available for child processes in case they need it. If the variable is not exported, most child processes will not be able to see a variable that you set in the current shell. It doesn't save anything and it doesn't "export" anything to the config files either, if that's what you thought.

Sorry make you misunderstanding. What I want to ask is, did the "export" write anything into the config files in the FS?

i92guboj 03-27-2009 08:43 AM

Quote:

Originally Posted by Paris Heng (Post 3489536)
Sorry make you misunderstanding. What I want to ask is, did the "export" write anything into the config files in the FS?

That's what I guessed :)

Then, as I explained in the previous post, the answer is "no". Export just marks the variable to be kind of "inherited" by child processes.

emaborsa 03-18-2011 12:50 PM

Quote:

Originally Posted by i92guboj (Post 3489552)
That's what I guessed :)

Then, as I explained in the previous post, the answer is "no". Export just marks the variable to be kind of "inherited" by child processes.

What have i to do to do the changes of the path permanently? Do i have to change the .bash_profile or bashrc? if Yes, how?

i92guboj 03-19-2011 03:22 AM

Quote:

Originally Posted by emaborsa (Post 4295217)
What have i to do to do the changes of the path permanently? Do i have to change the .bash_profile or bashrc? if Yes, how?

Code:

PATH="$PATH:/new/path"
# or
PATH="/new/path:$PATH"

Depending on whether you want your new path to appear before of after when searching for binaries.

The concrete file(s) where you should put this depends on which do you want. It's all explained in the bash man page, but, if you use bash just in terminal emulators (like konsole, gnome-terminal, xterm, etc.) then ~/.bashrc is probably your file.

http://www.gnu.org/software/bash/man...-Startup-Files


All times are GMT -5. The time now is 11:09 PM.