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 11-15-2006, 10:21 AM   #1
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
$PATH clean up?


Hi.

Running Suse 10.1 on an x86_64 machine. Basically my $PATH variable is cluttered with junk and repeats. I have only made a small number of additions to the variable via export PATH="$PATH:/somepath" in .bashrc. But when I do so and echo $PATH that entry will show up numerous times...here is the tail end of the output from echo $PATH for example:

..........
/usr/local/GMT3.4/bin:/usr/local/sac/bin:/usr/local/ham/ham-2.2.2/src:/usr/local/GMT3.4/bin:/usr/local/sac/bin:
/usr/local/ham/ham-2.2.2/src:/usr/local/GMT3.4/bin:/usr/local/sac/bin:/usr/local/ham/ham-2.2.2/src:
/usr/local/rdseed:/usr/local/GMT3.4/bin:/usr/local/sac/bin:/usr/local/ham/ham-2.2.2/src:/usr/local/rdseed/rdseed4.6:
/usr/local/GMT3.4/bin:/usr/local/sac/bin:/usr/local/ham/ham-2.2.2/src:/usr/local/rdseed/rdseed4.6:
/usr/local/GMT3.4/bin:/usr/local/sac/bin:/usr/local/rdseed/rdseed4.6:/usr/local/GMT3.4/bin:/usr/local/sac/bin:
/usr/local/SH-SHM/sh:/usr/X11/lib:/usr/X11/lib64:/usr/local/ham/ham-2.2.2/src:/usr/local/rdseed/rdseed4.6

Plus other entries that I've subsequently commented out of .bashrc remain - eg
/usr/local/rdseed was a mistake, to be replaced by usr/local/rdseed/rdseed4.6, and yet it remains part of the $PATH variable.

.bashrc is 'source'd after each edit.

Does anyone know why this is happening?

Thanks
 
Old 11-15-2006, 10:56 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Sometimes startup scripts will modify $PATH. Sometimes, I set out to find out exactly what is happening and usually wind up frustrated---but the answer is out there somewhere in a script.
 
Old 11-15-2006, 02:11 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
I'm not 100% clear what you mean by this "bashrc is 'source'd after each edit". Do you mean you do something like this
  1. start shell
  2. edit .bashrc, after which there are some 'export PATH="$PATH:something"' lines in it.
  3. source .bashrc
  4. check PATH contents
  5. edit again
  6. source .bashrc again

If you are doing this all in the same shell (i.e. not logging out / re-starting your terminal program/session), then it's clear.

The command
Code:
export PATH="$PATH:more"
sets the PATH to the existing value + ":more". Say your PATH starts out as "mypath:theoriginal"... after one execution of the export command the PATH would be "mypath:theoriginal:more". After another execution it would be "mypath:theoriginal:more:more" etc.

Sourceing the .bashrc simply feeds the contents of that file into the exitsing instance of the shell, so each time youo do it, you are appending more stuff to the PATH.

You should find that when you start a new shell (e.g. open a new terminal window or log out and log back in again), it will have the default PATH as set in the global shell config files (/etc/profile and friends), plus any customisations in your .bashrc).

One thing to note - be careful editing your .bashrc. If you make a typo which causes the shell to exit for any reason, you'll not be able to log in, because the shell will start and immediately quit! To protect against this, when editing it, always keep a window open which you can edit the .bashrc with while opening a new session to test your changes. The .bashrc will be read by the new session, but the existing session will stay unaltered while you test the new file... if you find a problem you can still edit the file in the original session.

The caution applies less to sessions in graphical environments that when you just have console access since the .bashrc probably won't affect a running X-Windows session, and you'll probably be able to launch editors and so on without having to start a shell which reads the [potentially broken] .bashrc.
 
Old 11-15-2006, 02:46 PM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
matthewg42 is probably right about the extent of redundancy you're seeing, but you'd probably see some in some cases, regardless.

I export cumulative things, such as paths, from ~/.bash_profile. This is generally executed only on login, so I don't get redundant entries with deeper shell levels. Knome terms stupidly default to 'TERM -ls', though, which would require changing or cancel out the distinction. Another option is to set the path in your .bashrc conditionally, with something like
Code:
if [ ! `echo $PATH|grep 'MYADDITION'` ]; then
       export PATH="$PATH:MYADDITION"
fi
which only appends it if it isn't already there.
 
Old 11-15-2006, 03:58 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Good point digiot. I like the term "knome", he he.
 
  


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
search path ($PATH) weird issue bricedebrignaisplage Linux - General 3 04-25-2007 04:41 AM
Image Path reference in Linux (Absolute path) javabuddy Linux - General 7 06-05-2006 07:45 AM
script to change unix path to windows path in all files csross Programming 8 04-29-2006 01:05 PM
Why is the value of $PATH in console mode different from the $PATH in xterm emulator? Akhran Debian 9 03-09-2006 06:10 PM
How to Chnage Python's module search path (sys.path)? lramos85 Linux - Software 1 05-02-2004 06:10 PM


All times are GMT -5. The time now is 12:23 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