Thursday, November 13, 2008

Add colour to output on command line in Linux

The following sequence can be used to change the colour of output in bash:
\e[x;ym foo \e[m Where:
  • \e[ means begin colour
  • x;y is a colour pair (refer to sources for colour codes)
  • \e[m means end colour
For example: toro@moutere:~$ echo -e "\e[0;31mfoo\e[mbar"
foobar
The -e tells echo to interpret the backslash sequences.

No comments:

Post a Comment