In shell script, echo display content with color display, echo display with color, parameter-e is required
The format is as follows:
Copy the codeThe code is as follows:
echo -e "\033[font background color; text color m string\033[0m"
For example:
Copy the codeThe code is as follows:
echo -e "\033[41;36m something here \033[0m"
The position of 41 represents the background color, and the position of 36 represents the color of the word
Note:
1. The background color of the character and the text color are in English.
2. There is an m after the text color
3. There can be no spaces before and after the string. If there is one, the output will also have spaces.
Below are the corresponding characters and background colors. You can try to find out different colors.
example
Copy the codeThe code is as follows:
echo -e “\033[31m Red Word \033[0m”
echo -e “\033[34m Yellow word \033[0m"
echo -e “\033[41;33m Yellow characters on red background \033[0m"
echo -e “\033[41;37m White characters on red background \033[0m"
Word color: 30--37
Copy the codeThe code is as follows:
echo -e “\033[30m Black Word \033[0m”
echo -e “\033[31m Red Word \033[0m”
echo -e “\033[32m Green word \033[0m"
echo -e “\033[33m Yellow word \033[0m"
echo -e “\033[34m Blue Word \033[0m”
echo -e “\033[35m Purple Word \033[0m"
echo -e “\033[36m Sky Blue Word \033[0m"
echo -e “\033[37m White word \033[0m”
Word background color range: 40--47
Copy the codeThe code is as follows:
echo -e “\033[40;37m White characters on black background \033[0m"
echo -e “\033[41;37m White characters on red background \033[0m"
echo -e “\033[42;37m White characters on green background \033[0m"
echo -e “\033[43;37m White characters on yellow background \033[0m"
echo -e “\033[44;37m White characters on blue background \033[0m"
echo -e “\033[45;37m White characters on purple background \033[0m"
echo -e “\033[46;37m White characters on the sky blue background \033[0m"
echo -e “\033[47;30m black letters on white background \033[0m”
Last control option description
Copy the codeThe code is as follows:
\33[0m Close all attributes
\33[1m Set high brightness
\33[4m Underline
\33[5m flashing
\33[7m reverse display
\33[8m vanishing
\33[30m — \33[37m Set the foreground color
\33[40m — \33[47m Set background color
\33[nA Cursor moves n lines up
\33[nB Cursor moves n lines down
\33[nC Cursor right-shift n lines
\33[nD Cursor moves left n lines
\33[y;xH Set cursor position
\33[2J Clear screen
\33[K Clear content from cursor to end of line
\33[s Save the cursor position
\33[u Restore cursor position
\33[?25l Hide cursor
\33[?25h Display the cursor