You are not logged in.

#1 2011-02-14 07:01:46

Lazar
Member
Registered: 2010-09-01
Posts: 14

[SOLVED]Why does .bash_profile seem tobe read in non-login shells too?

~/.bash_profile:

. $HOME/.bashrc

~/.bashrc:

export PATH=$PATH:$HOME/code/shell
(irrelevant lines left out)

(I have no ~/.profile, ~/.bash_login or * ~/.bash_logout. I have also never edited /etc/profile or /etc/bash.bashrc.)

I've read that in a login shell (e.g. TTY1) only the former is read, which in my case sources the latter. Running "export -p" in TTY1 gives a result consistent with this:
declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/home/lazar/code/shell" (/home/lazar/code/shell is only listed once)

I've also read that in a non-login shell (e.g. xterm) only the latter is read. However, when I run "export -p" in xterm or urxvt I get an unexpected result:
declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/home/lazar/code/shell:/home/lazar/code/shell" (/home/lazar/code/shell is listed twice!)
This implies that ~.bashrc is read twice, perhaps because .bash_profile is read in non-login shells too, even though it shouldn't be, should it? It doesn't seem to matter really, but I can't help but wonder why...


[EDIT]
I've found the answer. Exports from .bash_profile are done at boot time and *remain* active while X is active. Opening a non-login shell will cause .bashrc to export as well. Hence the duplication. My solution:

~/.bash_profile:

export PATH=$PATH:$HOME/code/shell
. $HOME/.bashrc

~/.bashrc:

(lines other than export commands)

Last edited by Lazar (2011-02-14 07:57:56)

Offline

Board footer

Powered by FluxBB