.bash_profile not sourced when running su
Using su
without -l
or -
starts bash
as an interactive, but non-login shell, which doesn't read from either of the files you specified. Use the -l
or -
option or put the relevant config into /root/.bashrc
.
Quick summary of config files:
- Login shell (
-l
/--login
) reads/etc/profile
first, and then the first it finds of:~/.bash_profile
,~/.bash_login
, and~/.profile
. - Interactive but non-login shell (
-i
) reads/etc/bash.bashrc
and~/.bashrc
, in that order (unless the--rcfile
option is used and tells it to look elsewhere). - Non-interactive shells, e.g. started from within another program without using the
-l
or-i
flags, reads the file specified in theBASH_ENV
environment variable. - When run as
sh
as a login shell, it will read/etc/profile
and~/.profile
, in that order. - When run as
sh
as an interactive non-login, it reads the file specified inENV
.
Bash behaves differently depending on if it believes that it is a login shell, i.e. the first shell run when you log onto a system. It only reads .bash_profile
if it is a login shell. If you put the PATH
-changing code into .bashrc
instead, it will be run for all interactive bash shells, not just login shells.