I'd like to make happen in RHEL/CentOS 7.6
anytime you do su
and become root I want the terminal prompt color in that terminal to become red for the duration of that su
session. Type exit
to go back to being whoever you were and I want the prompt color to go back to whatever the previous color was (black).
Same for an SSH window using putty logged in over the network: initially ssh in as user and have a default white shell prompt; do an su
to root and I want the prompt to become red; type exit I want the prompt to go back to white.
so far i did this but it's not working 100%, the color stays red after you type exit
and leave the su session and go back to being user.
/etc/profile.d/red_root_prompt.sh
if [ $UID -eq 0 ]; then
PS1="\e[31m[\u@\h \W]# "
else
PS1="[\u@\h \W]# "
Is there a way to make things happen the way I want? I only want it for bash shells.
su
orsu -
? I’d have thought the prompt would return to what ever it was before you elevated if you used the latter.su
, and the color thing has always worked in SUSE.tput
rather than embedding terminal-specific escape codes that will make a mess when you use some other terminal type. And don't forget\[…\]
around non-spacing output, or Bash will miscalculate line lengths.