Discussion:
bash troubles
lubos klokner
2005-12-20 17:03:32 UTC
Permalink
hello,

i'm using bash as shell for user root.
there is problem with /etc/bashrc and ~/.bashrc when i use "su -"
command. everything in these files is ignored, but when i use "su"
to change user to root, everything works fine and all aliases,
variables... are correctly loaded.

can you help me please ?

regards,
--
lubos klokner <***@klokner.sk>
Michal Moskal
2005-12-20 17:03:32 UTC
Permalink
Post by lubos klokner
hello,
i'm using bash as shell for user root.
there is problem with /etc/bashrc and ~/.bashrc when i use "su -"
command. everything in these files is ignored, but when i use "su"
to change user to root, everything works fine and all aliases,
variables... are correctly loaded.
can you help me please ?
From man bash:

When bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes com-
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.

[snip]

When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists. This
may be inhibited by using the --norc option. The --rcfile file option
will force bash to read and execute commands from file instead of
~/.bashrc.

Therfore login shell (as started with su -) will not read bashrc file.
You can overcome it by inserting . /etc/bashrc to /etc/profile (in bash
section), or . ~/.bashrc in ~/.bash_profile. In fact standard rc file
from PLD skel does it:

#v+
# .bash_profile - file executed when logging in

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
#v-
--
: Michal Moskal ::::: malekith/at/pld-linux.org : GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h
Jarosław Kamper
2005-12-20 17:03:32 UTC
Permalink
[...]
Post by Michal Moskal
Therfore login shell (as started with su -) will not read bashrc file.
You can overcome it by inserting . /etc/bashrc to /etc/profile (in bash
section), or . ~/.bashrc in ~/.bash_profile. In fact standard rc file
#v+
# .bash_profile - file executed when logging in
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
#v-
[***@pldworkstation jack]$ echo 'printf "ziew\n"' > ziew.sh
[***@pldworkstation jack]$ chmod 755 ziew.sh && sudo chown root.root ziew.sh
[***@pldworkstation jack]$ sudo mv ziew.sh /etc/profile.d/
[***@pldworkstation jack]$ sudo su -
ziew
[***@pldworkstation root]$
--
Jaros?aw Kamper <***@jack.eu.org>
Loading...