LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-16-2010, 01:03 PM   #1
nasridine
Member
 
Registered: Jan 2010
Posts: 52

Rep: Reputation: 15
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
 
Old 02-16-2010, 01:25 PM   #2
jvaldivia
Member
 
Registered: Sep 2007
Distribution: Debian Lenny
Posts: 61
Blog Entries: 2

Rep: Reputation: 19
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
 
Old 02-16-2010, 01:29 PM   #3
hostmaster
Member
 
Registered: Feb 2007
Posts: 55

Rep: Reputation: 17
Post your $HOME/.bash_profile and /etc/profile
 
Old 02-16-2010, 01:33 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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"
 
Old 02-16-2010, 01:53 PM   #5
nasridine
Member
 
Registered: Jan 2010
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
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?
 
Old 02-16-2010, 02:08 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by nasridine View Post
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.
 
Old 02-16-2010, 02:09 PM   #7
JimBrewster
Member
 
Registered: Feb 2010
Location: usa:/dev/random
Distribution: Slackware, Salix
Posts: 237

Rep: Reputation: 59
Code:
echo $PATH
...should show your full path.
 
Old 02-16-2010, 07:47 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
Old 02-16-2010, 07:54 PM   #9
nasridine
Member
 
Registered: Jan 2010
Posts: 52

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
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?
 
Old 02-16-2010, 11:03 PM   #10
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 849

Rep: Reputation: 201Reputation: 201Reputation: 201
(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
 
Old 02-17-2010, 07:05 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Quote:
Originally Posted by nasridine View Post
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.

Last edited by jschiwal; 02-17-2010 at 07:09 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 06:48 PM
set up java_home path in /home/user/.bashrc but use path in /usr/lib/java vitalstrike82 Slackware 4 01-14-2009 12:25 AM
sed attempting to replace text with directory path emgey Programming 5 04-03-2008 08:05 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 07:10 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 02:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration