Page 1 of 1

How do I make sure ~/.bash_profile is run?

PostPosted: Sep 17th, '12, 17:02
by jaywalker
This feels like a Basic Support issue. I cannot imagine that the answer is not forehead-slappingly obvious but I am having one of those days :(

The gory details:
Distribution: fully updated MGA2 on x86_64
Desktop is LXDE started from LXDM
Problem is my .bash_profile contains the standard
Code: Select all
PATH=$PATH:$HOME/bin
, but my PATH doesn't:
Code: Select all
[richard@Tureen ~]$ echo $PATH
/usr/lib64/libfm:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/games:/usr/lib64/qt4/bin


Can some kind soul please tell me where I should start looking for the solution?

Richard

Re: How do I make sure ~/.bash_profile is run?

PostPosted: Sep 17th, '12, 17:33
by alf
jaywalker wrote:PATH=$PATH:$HOME/bin


and PATH is exported in your .bash_profile?
Code: Select all
# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

Re: How do I make sure ~/.bash_profile is run?

PostPosted: Sep 17th, '12, 18:57
by jaywalker
Sorry, I was being too economical perhaps. The .bash_profile is completely standard, as originally installed, and the same as on three other systems and is as follows
Code: Select all
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
   . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
GB_GUI=gb.qt4

export PATH
export GB_GUI
unset USERNAME

OK, standard + the GB_GUI stuff which I added today as part of the same task to be able to easily start Gambas programs (in ~/bin) from the command line. Of course, the GB_GUI variable is not set either. I think this means that the ~/.bash_profile is not being run.

R

Re: How do I make sure ~/.bash_profile is run?

PostPosted: Sep 19th, '12, 21:18
by djennings
Maybe a silly question, but is ~/.bash_profile executable, and is it owned by your user?

If you have installed Mageia over an existing installation it is possible files in your home are owned by the wrong UID.

Re: How do I make sure ~/.bash_profile is run?

PostPosted: Sep 19th, '12, 23:41
by jaywalker
djennings wrote:Maybe a silly question, but is ~/.bash_profile executable


I have just checked two of my Mageia 2 installations, incidentally, both started life as Cauldron Beta2 (or was it 3) back in the day, and none of them has the execute bit set on .bash_profile. Nevertheless, the one I am using now does indeed have the $HOME/bin definition added to the PATH variable.

But that started me thinking. I read somewhere, probably in the bash man page, that you don't need the execute bit to be set if the contents of the file is "absorbed" somehow by some other script which is executing. I don't recall the technical term but I remember wondering at the time if might be something akin to an included file. Anyway, that must be what is going on here because none of the .bash_profile files is executable - not even the one on a Mandriva 2010 box.

I was hoping that someone might know how the ~/.bash_profile is run - surely something needs to "call" it or "include" it?

PS. And yes, I own them all (cackle, fiendish cackle, megalomaniacal guffaw)


Richard

Re: How do I make sure ~/.bash_profile is run?

PostPosted: Sep 19th, '12, 23:50
by martinw
~.bash_profile is only executed by a login shell. How are you starting bash? If it's being started by lxterminal, I think there's an option in lxterminal to cause the initial shell to be a login shell.

Re: How do I make sure ~/.bash_profile is run?

PostPosted: Sep 20th, '12, 00:56
by jaywalker
martinw wrote:~.bash_profile is only executed by a login shell. How are you starting bash? If it's being started by lxterminal, I think there's an option in lxterminal to cause the initial shell to be a login shell.


OK, I think I am getting somewhere. There is a file in /etc/lxdm (which is the display manager I use) called Xsession which has a line:
Code: Select all
[ -f ~/.profile ] && . ~/.profile


On this system (where ~/bin is correctly set in the PATH) ~/.profile is linked to ~/.bash_profile so that seems to explain that. This system also has an Xsession file in 4 locations, so I suppose one of them must be "the real thing". My money is on /etc/X11/Xsession
Code: Select all
[richard@Bathtub ~]$ locate Xsession
/etc/X11/Xsession
/etc/X11/xdm/Xsession
/etc/lxdm/Xsession
/usr/share/X11/xdm/Xsession


OK, I have had a poke through /etc/X11/Xsession. Man that looks complicated. My best guess at the moment is that something in all that complexity finds a good way to start LXDE (via the /etc/lxdm/Xsession file perhaps) but on the other system it loses track of where it is going but somehow still manages to start LXDE without going through /etc/lxdm/Xsession - hence no .profile leading to running .bash_profile.

I'll have another look when I'm not so tired. Thanks to all above.

Richard