shell—color processing
- In Linux shell or usual echo output, sometimes in order to distinguish the importance of certain strings, colors are often added to the output content to distinguish them. The following article mainly introduces the Shell output color and control, friends in need can refer to
Format
Format 1: echo -e "\033[background color; text color m characters to be output \033[0m"
Format 2: echo -e "\e[background color; text color m characters to be output \e[0m "
Example: blue text on green background
[root@xuegod63 ~]# echo -e "\033[42;34m hello world\033[0m"
[root@xuegod63 ~]# echo -e "\e[42;34m hello world \e[0m”
- For example: basket on green background
Note: The position of 42 represents the background color, the position of 34 represents the color of the word, and 0m is to clear all formats
1. There is an English semicolon ";" between the background color of the text and the text color.
2. There is an m
after the text color. 3. There can be no spaces before and after the string. If there are any, the output will also have spaces.
4. Echo display band Color, you need to use the parameters -e
-e to allow interpretation of the characters listed below with backslash escaped.
- Control options:
\033[0m close all attributes
\033[1m set high brightness and bold
\033[5m flashing
After execution, it is found that all outputs are flashing in the later stage. How to turn off?
You can use \033[0m to close all properties
Common shell input color text: 3x represents the color of the word, 4x represents the background color
-
echo -e "\033[30m black words\033[0m"
echo -e "\033[31m red words\033[0m"
echo -e "\033[32m green words\033[0m"
echo -e "\ 033[33m yellow characters\033[0m”
echo -e “\033[34m blue characters\033[0m”
echo -e “\033[35m purple characters\033[0m”
echo -e “\033[36m sky blue Word \033[0m"
echo -e "\033[37m white word\033[0m" -
echo -e "\033[40;37m white on black background\033[0m"
echo -e "\033[41;37m white on red background\033[0m"
echo -e "\033[42;37m white on green background\ 033[0m"
echo -e "\033[43;37m white on yellow background\033[0m"
echo -e "\033[44;37m white on blue background \033[0m"
echo -e "\033[45;37m White on the purple background \033[0m"
echo -e "\033[46;37m White on the sky blue background \033[0m"
echo -e "\033[47;30m Black on the white background \033[0m"