Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Been trying to change the color of the shell prompt for each user including root. The things I've tried so far do change the color for each user but don't change the su (root) prompt back to bright red. The su color remains what is set for the user.
The code I've been using is in ~/.bashrc
Code:
### colorize user shell prompt: 2/12/10 TTT
# export PS1="\e[0;36m\u@\h \w> \e[m " # base colored prompt
# colors: # replace 0 with 1 for bright color:
# black 0;30
# blue 0;34
# green 0;32
# cyan 0;36
# red 0;31
# purple 0;35
# brown 0;33
# Change prompt for root
if test "$UID" -eq 0 ; then <========== this doesn't seem to work
color="1;31m" # bright red for su(root)
else
color="0;36m" # color for user
fi
export PS1="\e[$color\u@\h \w> \e[m "
Should this be put somewhere else or is the code wrong?
Admittedly I'm a bash script newbie, normally using c or assembly.
That doesn't do what I want. That just changes the "$" for ordinary user with "#" for su(root). The color stays the same. I want to change the color each user selects while retaining the bright red when the user goes su(root).
In unmodified bash prompts, the user prompt is the default color (usually black) while the su(root) prompt changes to bright red.
Your suggestion did give me some ideas about what to research further. Again, thanks.
I guess I'm not sure what you're trying to do then. I have my user prompt set to brown. When I enter su, enter password and get root prompt it is red. What exactly do you want to change? The entry I posted above was from my user .bashrc, the following, which as you can see is different, is from my root .bashrc:
export RESET='\e[0m'
export BRED='\e[1;31m'
export BGREEN='\e[1;32m'
export BBLUE='\e[1;34m'
export BMAGENTA='\e[1;35m'
XTITLE='\e]0;\u:\W\a' # \W is the base directory name.
if [ "$PS1" ]; then
if [[ "$TERM" =~ xterm ]]; then
# Set the prompt
# Must unquote all the variables.
if [ "$(id -u)" -eq 0 ]; then
export PS1='\['${XTITLE}$BRED'\]\u:[\['$MAGENTA'\]$(variprompt)\['$BRED'\]]##\['$RESET'\] '
else
export PS1='\['${XTITLE}$BGREEN'\]\u:[\['$BBLUE'\]$(variprompt)\['$BGREEN'\]]$\['$RESET'\] '
fi
else
# Prompt for non xterm consoles--leave out the xterm title setting.
if [ "$(id -u)" -eq 0 ]; then
export PS1='\['$BRED'\]\u:[\['$MAGENTA'\]$(variprompt)\['$BRED'\]]##\['$RESET'\] '
else
export PS1='\['$BGREEN'\]\u:[\['$BBLUE'\]$(variprompt)\['$BGREEN'\]]$\['$RESET'\] '
fi
fi
fi
variprompt is a script I wrote (later converted to a function) that outputs the current directory string based on the current terminal width.
Last edited by David the H.; 02-28-2010 at 11:10 PM.
Reason: bunged up the link
No per-user configuration is done by the su command without the "-" option. If you want per-user configuration to be done when using su, change to su - and su will run the usual shell initialisation, as if the user was logging in.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.