Hack 38. Change background color of the prompt

by Ramesh

Change the background color by specifying \e[{code}m in the PS1 prompt as shown below.

  1. $ export PS1="\e[47m\u@\h \w> \e[m "
  2.  
  3. [Note: This is for Light Gray background]

Combination of background and foreground.

  1. $ export PS1="\e[0;34m\e[47m\u@\h \w> \e[m "
  2.  
  3. [Note: This is for Light Blue foreground and Light Gray background]

Add the following to your ~/.bash_profile or ~/.bashrc to make the above background and foreground color permanent.

  1. $ vi ~/.bash_profile
  2. STARTFGCOLOR='\e[0;34m';
  3. STARTBGCOLOR="\e[47m"
  4. ENDCOLOR="\e[0m"
  5. export PS1="$STARTFGCOLOR$STARTBGCOLOR\u@\h \w> $ENDCOLOR"

Play around by using the following background color and choose the one that match your taste:

  • \e[40m
  • \e[41m
  • \e[42m
  • \e[43m
  • \e[44m
  • \e[45m
  • \e[46m
  • \e[47m