~/.bashrc sourced twice?


I just installed openSUSE 11 RC. I have my $PATH definition in my home ~/.bashrc file, and everything was fine with SuSE 10.3 (however on another computer). Now, my $PATH variable contains twice every element defined in .bashrc.

It thus seems that the PATH defined in this file is sourced twice, which shouldn’t be the case, right?

It seems to me that it is read once then bash is invoked and once at login, since when I delete the file and relaunch the terminal without logging out, I got only one copy of the PATH. Whenever I logout, I then have none anymore. If then I login, I have none of the elements, and if I recreate the .bashrc file, and close the terminal and relaunch, I have again one. If I subsequently logout and login, I have two copies again…

Any ideas or suggestions?


could you post the output of the command

 *echo $PATH*

Sure! It’s quite long… but as you may see, everything is repeated from /home/me/bin.

(output anonymized, newlines added for readability. Repeat is not an c/c error)


And here is my .bashrc (anonymized, too)

#echo "Reading ~/.bashrc"


# various programs

# MUMmer
# phredphrap
export CONSED_HOME=/opt/bio/phredphrap

# annotation pipeline (temporary)

#art/act (Artemis Comparison Tool)
alias act='/home/other/lib/GENOME/artemis/act'
alias art='/home/other/lib/GENOME/artemis/art'

#Glimmer 3
export G3_SPATH=/home/other/lib/GENOME/glimmer3.01/scripts
export G3_PATH=/home/other/lib/GENOME/glimmer3.01/bin

#nt/aa matrices for BLAST
#export BLASTMAT=/opt/bio/data/blast/matrix/aa
export BLASTMAT=/opt/bio/bin

# coloring ls command
alias ls="ls --color"
#export LSCOLORS=dxfxcxdxbxegedabagacad

export LS_COLORS

# fancy terminal
export PS1="\h:\w\$: "

# changing umask to have writing access for group
umask 002

# export PATH
export PATH

hmm that’s weird i do not have $PATH set in my .bashrc file (i use Bash shell though), in any of my computers, however they are all running different versions than 11… so i cannot make valid comparison.

Anyway could you inspect your file /etc/profile
and paste those lines that follow a commented line that says
# Make path more comfortable
Until the next commented line
Not sure if you have it (i am looking at my 10.3) but if so, inspecting those might give us some clues

There it is:

# Make path more comfortable
if test -z "$PROFILEREAD" ; then
    if test "$HOME" != "/" ; then
	for dir in $HOME/bin/$CPU $HOME/bin ; do
	    test -d $dir && PATH=$dir:$PATH
    if test "$UID" = 0 ; then
	test -d /opt/kde3/sbin  && PATH=/opt/kde3/sbin:$PATH
    for dir in	/usr/X11/bin \
		/usr/bin/X11 \
		/usr/X11R6/bin \
		/var/lib/dosemu \
		/usr/games \
		/opt/bin \
		/opt/kde3/bin \
		/opt/kde2/bin \
		/opt/kde/bin \
		/usr/openwin/bin \
	test -d $dir && PATH=$PATH:$dir
    unset dir
    export PATH

I remarked another strange behavior… When I renamed .bashrc .profile in my home dir, and logged out/in, I still had the PATH set correctly (and only once), but all the rest (aliases, PS1 export, LS_COLORS) was not set correctly. For example, there are a couple of aliases (like alias xxx=“ssh -X me@aaa.bbb.ccc.net”, that I removed from the file pasted above) that work quite well with .bashrc, but not with .profile…

That part of the /etc/profile is identical to mine.
If you are using bash, you should put stuff in .bashrc, not in .profile, which (as far as i know) is used for the shells ksh or sh.
My .profile file for example has one line only that is uncommented, which is just test -z “$PROFILEREAD” && . /etc/profile.
Now the cause of the double entries in your path might just be the fact that you are trying to edit the ~/.profile duplicating over there entries that are already in .bashrc… not sure if i understand well: is this what you are doing?
Can you post your ~/.profile content ?

First, and above all, thanks for your precious help… Should have started with that :wink:

I don’t use .profile and .bashrc at the same time. I use only .bashrc, and the .profile thing was just to try something. Normally, I don’t even have a .profile file in my home…

I have to add that I had exactly the same .bashrc on a SuSE 10.3 (but on another computer), and that it was working quite well (however I was accessing it with ssh).

Ok i see.
I was tempted to say to try commenting all the entries in .bashrc that have $PATH. However if your other machine does have the same entries, it might be the wrong point where to look for errors.

Do you have a file
/etc/bash.bashrc.local ?
I personally do not have, it does not even exist on my system. But if for some reasons it was created, it might be the cause of the anomalies, as it duplicates the entries in .bashrc

If you do not have that file, well i would try to comment out the entries in .bashrc that deal with PATH. In the worst case, even if you are no longer able to login normally as a user, you can always login as root and remove the comment symbols from the file, thus restoring the previous situation.

As you, I don’t have a /etc/bash.bashrc.local.

I commented all PATH entries (setting PATH and export), log out/in, and now my $PATH looks like:


to me that looks a lot more normal now than before.
See this is mine:


this is yours


My suggestion is going on this way, if you ever encounter any problems in installing applications you can always add manually setting the path.
But i doubt you will have lots of problems, as i have been installing and manually compiling lots and lots of apps and never had any problems at all with paths

It is less messy indeed, but my programs are not in my PATH any more, which is very inconvenient :wink:

Well, where should I put them, then?

Actually, it’s OK if I have them twice, even though it is not very clean. I thought this might have been a bug, and I should report it… your opinion?

And, again, thanks a lot for your precious help!

Well first of all normally program links should be in one of the folders existing in your path.
In fact if you open for example /usr/bin you will see a great amount of the programs you normally use is there. You dont need to add a path to each program folder, when you install any program (either compiling manually or through yast or through the rpm command) normally a link or the executable goes to one in the standard directories, such as /usr/bin.
Otherwise if for each new installed program you should add an entry to your path it would become just a mess and the lookup process when you type a command would be very time consuming

Now if you want, for some reasons, to add in your path another directory that is not there (make sure you really need that… that is, if you get an error): just add in you .bashrc and entry with $PATH=[path to the programs you want]
But ONLY to that directory: thats added to your existing path, it does not replace. So you must not add all the rest.

Yeah a double entry for the path wont change a lot but the lookup process when you type a command (lookup to check if that command is in your path) might be slightly longer, cuz it will lookup twice any folder listed there, until the command is found