Discussion:
[Fluxbox-users] My .profile is not read?
John W
2011-09-15 03:56:53 UTC
Permalink
Hi,

I recently started trying out fluxbox, and while I am generally happy,
something is wonky with how my shell starts up.
I have various env. vars set up in my .profile, and some aliases in my
.bashrc, etc.

Yet, when I spawn a new xterm from within fluxbox, I get a vanilla
instance of bash - it does not read my .profile.

I do not have this issue, for example, when spawning an xterm from inside Xfce.

I'm not sure if it's really fluxbox related or some other X issue, but
any pointers would be appreciated.

Note: I am launching fluxbox from a shell that has everything set up
right (has my custom prompt, etc from .profile), but fluxbox doesn't
seem to want to inherit that stuff.

Thanks
-John
Raphaël Droz
2011-09-16 10:10:11 UTC
Permalink
Post by John W
Hi,
I recently started trying out fluxbox, and while I am generally happy,
something is wonky with how my shell starts up.
I have various env. vars set up in my .profile, and some aliases in my
.bashrc, etc.
Yet, when I spawn a new xterm from within fluxbox, I get a vanilla
instance of bash - it does not read my .profile.
I do not have this issue, for example, when spawning an xterm from inside Xfce.
I'm not sure if it's really fluxbox related or some other X issue, but
any pointers would be appreciated.
Note: I am launching fluxbox from a shell that has everything set up
right (has my custom prompt, etc from .profile), but fluxbox doesn't
seem to want to inherit that stuff.
.profile is read by login shell [1]
your xterm does not run a *login* shell thus only reads .bashrc.

.profile exported values will affect fluxbox and xterm *if* fluxbox itself
was launched into a login shell (or if the shell used to run fluxbox
from loaded your .profile in some way).


Some people often do things like this in .bashrc:

[[ -z $PROFILE_LOADED ]] && . .bash_profile
# make sure that .bash_profile does not load .bashrc BEFORE setting up $PROFILE_LOADED

But you can also configure your login manager (qingy, gdm, ...) to use
your .xsession file to run X.
For example here is mine:

#!/bin/bash

# some stuff with variables like MAILDIR, HISTCONTROL + loading common
# routines from .bashrc.d/common_profile/*.sh
[[ "$ENV_BP" != yes && -r $HOME/.bash_profile ]] && . $HOME/.bash_profile

# define the profile to use, eg ENV_PROFILE=desktop or ENV_PROFILE=eeepc, ...
[[ "$ENV_BC" != yes && -r $HOME/.bashrc.d/profile ]] && . $HOME/.bashrc.d/profile

# my equivalent to .fluxbox/startup file (will also setup $ENV_WM_CONFIG)
__env_loader "$HOME/.xinitrc.d/$ENV_PROFILE"

# exec fluxbox
exec /usr/bin/fluxbox -verbose -log $ENV_SOURCE/.fluxbox/log -rc $ENV_WM_CONFIG


regards


Raph

[1] man bash, chapter "INVOCATION", look for "interactive" mode.
John W
2011-09-17 00:28:15 UTC
Permalink
Post by Raphaël Droz
.profile is read by login shell [1]
your xterm does not run a *login* shell thus only reads .bashrc.
.profile exported values will affect fluxbox and xterm *if* fluxbox itself
was launched into a login shell (or if the shell used to run fluxbox
from loaded your .profile in some way).
Yes, I phrased my initial question badly; sorry about that.

After doing some more research, it seems that the real problem is that
PS1 (my custom prompt) somehow is getting overwritten when fluxbox
runs.

I was setting up PS1 in my .profile.
Normally, this env. var is inherited by subprocesses, so I would have
the correct PS1 in subsequent shells.

But for some reason fluxbox overwrote it with some 'default' value - I
don't know why that happened, or if it is configurable. I didn't find
cause for this in any obvious places, or in the documentation.
Everything *else* from my .profile was inherited correctly, which is
why I feel fairly confident in saying that something in fluxbox
overwrote it.

So ultimately, when I launched new xterm processes inside fluxbox,
they had the wrong PS1.

As a workaround, I put my PS1 definition in my .bashrc rather than my .profile.
Since .bashrc does get read every time a (non-login) shell is
launched, it gave me my special prompt.


If anyone knows why fluxbox seems to be messing with PS1 on startup,
I'd be curious to know.
But the workaround is fine for me, too.

-John
Raphaël Droz
2011-09-19 13:27:10 UTC
Permalink
Post by John W
But for some reason fluxbox overwrote it with some 'default' value - I
don't know why that happened, or if it is configurable. I didn't find
cause for this in any obvious places, or in the documentation.
Everything *else* from my .profile was inherited correctly, which is
why I feel fairly confident in saying that something in fluxbox
overwrote it.
I don't think fluxbox changes $PS1...
Post by John W
So ultimately, when I launched new xterm processes inside fluxbox,
they had the wrong PS1.
...but rather the .bashrc which is loaded by xterm.
(look deeply for what happens in your .bashrc)

Try the following in .fluxbox/keys
Control BackSpace :Exec export -p > /tmp/env_dump.log
(then when fluxbox is up, you can dump its environment)

Or:
export -p > /tmp/env-before-bashrc.log at the beginning of .bashrc.
Post by John W
As a workaround, I put my PS1 definition in my .bashrc rather than my .profile.
Since .bashrc does get read every time a (non-login) shell is
launched, it gave me my special prompt.
.bashrc is where is located my $PS1 too.
.bash_profile is where I try to put daemons like jackd, irexec, mpd,
some aliases and $PATH modifications (it uses [[ bash-syntax ]] )
Post by John W
If anyone knows why fluxbox seems to be messing with PS1 on startup,
$ grep -r PS1 ~/comp/sources/fluxbox # brought nothing

is your $PS1 really exported ?


Raph
John W
2011-09-23 04:39:50 UTC
Permalink
Hi, I spent a little more time looking at this.
Post by Raphaël Droz
(look deeply for what happens in your .bashrc)
My .bashrc is very simple - it sets some aliases, sets some bash
options (eg: 'set -o vi'), and creates some shell functions.

Further, this worked before in Xfce, so if something in .bashrc were
messing it up, wouldn't it have happened then as well?
Post by Raphaël Droz
Try the following in .fluxbox/keys
Control         BackSpace :Exec export -p > /tmp/env_dump.log
(then when fluxbox is up, you can dump its environment)
export -p > /tmp/env-before-bashrc.log at the beginning of .bashrc.
I tried these. I also put an 'export -p > ...' in my .xinitrc, just
before the final 'exec fluxbox'.
The results:

* in .xinitrc, just before fluxbox is run, PS1 is set correctly and exported
* when dumping from the key shortcut, PS1 is blank and not exported
* when dumping from .bashrc, PS1 is set wrong (some default prompt?)
and not exported
Post by Raphaël Droz
$ grep -r PS1 ~/comp/sources/fluxbox # brought nothing
Yeah, I poked around there too; didn't find anything, either.
Post by Raphaël Droz
is your $PS1 really exported ?
It is before I invoke fluxbox. But it isn't afterwards.
No idea why ):

-John

Continue reading on narkive:
Loading...