1

I am in the midst of learning Linux, specifically the BASH Shell. I have been trying to edit the initialization files so that whenever I su into root, my prompt will turn red. I am using the code posted below. I am placing the code into the .bashrc file, but have also tried /etc/profile and .bash_profile. If I manually source the files my prompt will turn red for root only like I want, however, if I issue su without sourcing my prompt remains unchanged?

if [ $EUID -eq 0 ]; then
        PS1='\e[0;31m[\u@\h \W]\$ \e[m' 
else
        PS1='[\u@\h \W]\$ ' 
fi

1 Answer 1

1

su usually doesn't load the new user's profile scripts by default. Use su -l to solve this.

3
  • Is there another configuration file in which su reads that I could just add source /etc/profile Commented Sep 16, 2019 at 12:03
  • My workaround for this is to set alias su='su -l' in my user's profile (e. g. ~/.bash_aliases). Commented Sep 16, 2019 at 12:06
  • 1
    I actually figured out the ultimate issue. I was in the wrong directory. Using su to change to root still left me in the /home/user directory. I needed to create a .bashrc in the /root directory Commented Sep 16, 2019 at 22:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.