Introduction: Because in the C code to see the printing color word, and PS1 want to know more, only this blog post.
----------------------------------------
Linux Terminal Console Font Color
----------------------------------------
Linux Terminal console font color, using an escape sequence
\e[f; B;om
The \e escape character starts, and the ESC ASCII code is 27, which equals 033 in octal notation.
\e or \033 declares the beginning of the escape sequence,
[Start defining colors.]
' F ' for font color, number 30~37;
' B ' is the background color, number 40~47.
' O ' for special meaning code
Their order is not related.
M is the mark
m not followed by spaces, is defined by the color Word and background
Color table
Foreground background color
-------------------------
30 40 Black
31 41 Red
32 42 Green
33 43 Yellow
34 44 Blue
35 45 Magenta
36 46 Cyan
37 47 White
Special code meaning
-------------------------
0 OFF
1 highlighting
4 Underline
5 Flashing
7 Anti-white display
8 Not visible
Application 1: Interpreting the colored PS1
ps1= "\[\e[32m\][\[email protected]\h \w]$\[\e[m\]"
Explanation: \[\] for group representation
Define [\[email protected]\h \w]$ as foreground color green. Then restore the default settings.
Application 2: Use the console to output color or color backgrounds
Echo-e "\033[34;1mthis is high lighted blue \033[0m"
C Code: printf ("\033[34;1mthis is high lighted blue \033[0m\n");
The tail \033[0m restores the system default color
Linux Terminal Color Control