Satya's blog - bash and tcsh colors

Nov 12 2007 10:52 bash and tcsh colors

To set colors in tcsh, and in bash for that matter, and possibly other shells as well, use this:

echo ESC[0\;42\;30m

Replace ESC with a literal escape, usually achieved by ctrl-v followed by the escape key. The first number, 0, sets attributes like bold, etc. The second number, 42, sets the background color. It is optional, you can as well do "0;30m" instead of "0;42;30m" as I have above. The semi-colons (;) are escaped with backslashes (\). The third number, 30, is the foreground color. You echo again with all the numbers set to 0 to get the "normal" colors. (Actually, it is enough for the last number to be 0.) The codes are:

First number:
0 - normal
1 - bold
2 - normal again
3 - background color
4 - underline the text
5 - blinking

Foreground colors (3rd number):
30 - black
31 - brick red
32 - green
33 - yellow ochre
34 - dark blue
35 - magenta
36 - cyan
37 - white/gray

The background color code is same as the foreground coe, with 10 added to it. Background of red can be achieved with code 41.

Cribbed from, but I like to think my explanation is clearer. That site tells you how to embed the codes into a prompt string.