The numbers in the above table work for xterm terminal.Result may vary
for other terminal emulators.
Use the following template for writing colored text.
echo -e "\033[COLORm Sample text"
The "\033[" begins the escape sequence.You can also use "\e[" instead
of "\033[". COLOR specifies a foreground color, according to the table
above.The "m" terminates escape sequence, and text begins immediately
after that.
Note: With an echo, the -e option enables the escape sequences.You can
also use printf instead of echo.
printf "\e[COLORm sample text\n"
To print Green text
echo -e "\033[32m Hello World"
or
printf "\e[32m Hello World"
The problem with above statement is that the blue color that starts
with the 32 color code is never switched back to the regular color, so
any text you type after the prompt and even prompt also is still in the
Green color.
To return to the plain, normal mode, we have yet another sequence.
echo -e "\033[0m"
Now you won't see anything new on the screen, as this echo statement
was not passed any string to display. But it has done its job, which
was to restore the normal viewing mode. Whatever yor type now will be
avoid of any fancy effects.
Escape sequence also allow you to control the manner in which
characters are displayed on the screen.
The following table summarizes numbers representing text attributes
in Escape Sequences.

ANSI CODE

Meaning

0

Normal Characters

1

Bold Characters

4

Underlined Characters

5

Blinking Characters

7

Reverse video Characters

Note: Blink attribute doesn't work in any terminal emulator, but it
will work on the console.
Combining all these Escape Sequences, you can get more fancy effect.
Use the following template for writing colored text on a colored
background.
echo -e "\033[COLOR1;COLOR2m sample text\033[0m";
The semicolon separated numbers "COLOR1" and "COLOR2" specify a
foreground and a background color.The order of the numbers does not
matter, since the foreground and background numbers fall in non-
overlapping ranges."m" terminates the escape sequence, and the text
begins immediately after that.Although setting the colors separately
also work (i.e. \033[44m\033[32m).
There are some differences between colors when combining colors with
bold text attribute.
The following table summarises these differences.