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?

2

2 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.

2

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 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.