Changing Prompt Color In Bash Shell Based On Userid


Edit your /etc/profile file & append the below text to change prompt-color to red when logged-in as root & to green when logged in as normal user 🙂

if [ $(id -u) -eq 0 ]; #if userid is 0, then change prompt color to red.
then
export PS1="\e[0;31m[\u@\h \W]\$ \e[m"
else # change prompt to green
export PS1="\e[0;32m[\u@\h \W]\$ \e[m"
fi

Caveat – The prompt will be $ in both the cases. I tried changing that to # but that echoed a numerical digit instead 😦

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s