LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to replace path (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-replace-path-789515/)

nasridine 02-16-2010 12:03 PM

how to replace path
 
I added a path in my bash_profile so that I could use the executables in the directory (I thought). But it turned out some other directory has the same executables and the path had already been added by the previous user. Is there way to overwrite this path? I can't find where that old path was added. Thanks

jvaldivia 02-16-2010 12:25 PM

review your .basrh file, you may have a line like:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

If so review the file /etc/bash_completion.

Jose Valdivia
Blog: http://soad1982.blogspot.com

hostmaster 02-16-2010 12:29 PM

Post your $HOME/.bash_profile and /etc/profile

jschiwal 02-16-2010 12:33 PM

You could simply add your path to the beginning instead of the end.

If you know which path was is causing the problem, you could use sed to replace it at the end of your PATH= statement. Or you could delete it from PATH, and add it to the end in the right hand side of your assignment.
example moving ':/usr/games' to the end of the PATH variable.

PATH="${PATH/\/usr\/games:/}:/usr/games"

nasridine 02-16-2010 12:53 PM

Quote:

Originally Posted by jschiwal (Post 3865866)
You could simply add your path to the beginning instead of the end.

If you know which path was is causing the problem, you could use sed to replace it at the end of your PATH= statement. Or you could delete it from PATH, and add it to the end in the right hand side of your assignment.
example moving ':/usr/games' to the end of the PATH variable.

PATH="${PATH/\/usr\/games:/}:/usr/games"

I know which path is causing the problem. Just that I can't find where it is. Not in .bash_profile, nor /etc/profile. Where else to look?

catkin 02-16-2010 01:08 PM

Quote:

Originally Posted by nasridine (Post 3865892)
I know which path is causing the problem. Just that I can't find where it is. Not in .bash_profile, nor /etc/profile. Where else to look?

Check all the Bash Startup Files.

JimBrewster 02-16-2010 01:09 PM

Code:

echo $PATH
...should show your full path.

jschiwal 02-16-2010 06:47 PM

There may be an /etc/profile.d/ directory which contains scripts that are sourced by profile when you login. Sometimes there is also an /etc/profile.local file that is sourced and intended for your own system changes. Your distro my want /etc/profile left alone in case changes need to be made, or it sources functions that the system uses, or just to prevent you from removing the lines that source the /etc/profile.d scripts.

nasridine 02-16-2010 06:54 PM

Quote:

Originally Posted by jschiwal (Post 3866209)
There may be an /etc/profile.d/ directory which contains scripts that are sourced by profile when you login. Sometimes there is also an /etc/profile.local file that is sourced and intended for your own system changes. Your distro my want /etc/profile left alone in case changes need to be made, or it sources functions that the system uses, or just to prevent you from removing the lines that source the /etc/profile.d scripts.

Yes you are right. There are a lot of .sh files in the /ect/profile.d/ directory which include path for each program. I assume these files were generated when each of the packages was installed, right?

AnanthaP 02-16-2010 10:03 PM

(1) which <program name> will tell you which (from where in the PATH variable), the <program name> is picked up for execution.

(2) To be sure add it in your .bash_profile (the final one to be executed and which is tailored for your environment) thus
Code:

PATH=<myPath>;$PATH
export $PATH

Note that as suggested by other posters, your path is added first and so will be scanned first.

End

jschiwal 02-17-2010 06:05 PM

Quote:

Originally Posted by nasridine (Post 3866223)
Yes you are right. There are a lot of .sh files in the /ect/profile.d/ directory which include path for each program. I assume these files were generated when each of the packages was installed, right?

That is often the case. A package that supplies a device driver will drop a file in /etc/modprobe.d/ instead of using sed in a script to modify /etc/modprobe.conf. The same for services dropping their settings for xinetd and for logging. It reduces the possibility of one package accidently effecting settings for another one. It is also possible that your distro's admin program (like yast2) will add or remove settings as well, such as when enabling or disabling a service or setting.


All times are GMT -5. The time now is 05:30 PM.