DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   bash (http://www.daniweb.com/code/bash.html)
-   -   Change color according to user (http://www.daniweb.com/code/snippet776.html)

ankur.dhoot bash syntax
Oct 25th, 2007
This code changes color of prompt according to user, suppose if user is root then color would be red and normal user would have color black. This'll diffrentiate in users.

  1. if [ $(id -u) -eq 0 ];
  2. then # you are root, set red colour prompt
  3. PS1="\[$(tput setaf 1)\]\u@\h:\w #\[$(tput sgr0)\]"
  4. else # normal
  5. PS1="\u@\h:\w $"
  6. fi