Thursday, April 8, 2010

Colored output in bash

Use escape sequences:

echo -e '\E[color1;color2mYour Text.'
(color1 is the foreground, color2 the background color)

Shell Scripting Syntax


  1. echo -e '\E[30m black \E[31mred \E[32mgreen \E[33myellow \E[34mblue \E[35mmagenta \E[36mcyan \E[37mwhite'
  2. echo -e '\E[30;41mblack on red'


Shell Scripting Syntax
  1. Color: Foreground: Background:
  2. ---------------------------------------------------------
  3. black 30 40
  4. red 31 41
  5. green 32 42
  6. yellow 33 43
  7. blue 34 44
  8. magenta 35 45
  9. cyan 36 46
  10. white 37 47