Change terminal command prompt for root user in Sierra

bashcommand linerootterminal

I can change the bash command prompt for the Terminal for an ordinary user without issue. (In my case, I modified the $PS1 variable in /etc/bashrc.) However, that change does not modify the command prompt when one elevates privileges to root using sudo -s.

Does anyone know where the command prompt preference is stored on a macOS Sierra (10.12.5) machine for an admin user who has elevated his privileges to root using sudo -s?

I have tried modifying the following files…

  • /var/root/.bash_profile
  • /var/root/.bash_rc
  • /var/root/bash_rc
  • /var/root/.profile
  • ~/.profile

I have also tried using the command export PS1="Some prompt here# ", which changes the root prompt temporarily, but it does not stick when the session is ended and a new one is started.

Best Answer

From the sudo manual:

-s, --shell    Run the shell specified by the SHELL environment variable if it is set or the shell
               specified by the invoking user's password database entry.  If a command is specified, it
               is passed to the shell for execution via the shell's -c option.  If no command is
               specified, an interactive shell is executed.

An interactive shell would read the invoking user's .bashrc. So, Tony Williams' solution would work if it is in your .bashrc. But da4's solution should also work if it is placed in your .bash_profile.