I switch to another user using the command:
sudo -u dsc -i After the command executions moves to the home directory /home/dsc .
However, the .bashrc file in this directory is not executed. Why this happens?
22 Answers
sudo -i starts a login shell; .bashrc is only executed for non-login interactive shells. One of .bash_profile, .bash_login, or .profile should have been executed, though.
I noticed that su -l as well as sudo -i was indeed not loading the .bashrc file.
However, after I added a .profile file (in this case at /root/.profile) that loads the .bashrc file when present, everything works fine
# if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi