Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > Programming > Bash Script > Output in Colors

Outout in Colors

iDog

We can print strings in colors by using escape sequence:


echo "^[[0;36;40mXXXXXX^[[0m"

Notes:

  1. "^[[" contains two characters: an Esc (press <Ctrl>-V, then Esc key), and a '['.
  2. We need to 'close' the color instruction by ending with "^[[0m", otherwise the color is to be used in all the terminal.

Syntax:


^[[<attr>;<fore_color>;<back_color>m

If any of the above three values is omitted, then the default value is used. Attributes

ValueMeaning
0Reset All Attributes (return to normal mode)
1Bright (Usually turns on BOLD)
2Dim
3Underline
5Blink
7Reverse
8Hidden

Foreground colors

ValueMeaning
30Black
31Red
32Green
33Yellow
34Blue
35Magenta
36Cyan
37White

Background colors

ValueMeaning
40Black
41Red
42Green
43Yellow
44Blue
45Magenta
46Cyan
47White