When you run the script, you need to change the color of the text to improve the readability of the standard output.
The echo command and the printf command enable this functionality.
Formatted output can be implemented using the printf command, which makes the results of the script run more standardized and readable.
First introduce some common parameters of echo command
Echo-n remove echo output line end default newline character
ECHO-E enable the conversion of the backslash control character, which is exactly what this article requires.
Echo-e turn off the conversion of the backslash control character
Shell scripts use the Echo display text color (echo-e followed by parameters that can be used directly with the printf command) to use the escape sequence string to the shell, an escape sequence character is a control command that controls the shell to perform a particular action.
Escape sequences are usually started with ESC and are recorded as ^[in the shell, where the ^ octal is recorded as 033, and an escape sequence character is enclosed in \033 and \033[.
The format is as follows:
Echo-e "\033[word background color; text color m string \033[0m"
Where \033 means that esc,\033[0m in the ASCII table means that all properties are turned off, that is, the default value is restored
Word background color range: 40-47
40: Black 41: Red 42: Green 43:***
44: Blue 45: Purple 46: Cyan 47: White
Echo-e "\033[40;37m Black Bottom White \033[0m"
Echo-e "\033[41;37m Red bottom White \033[0m"
Echo-e "\033[42;37m Green bottom White \033[0m"
Echo-e "\033[43;37m Yellow \033[0m"
Echo-e "\033[44;37m Blue bottom White \033[0m"
Echo-e "\033[45;37m Purple \033[0m"
Echo-e "\033[46;37m sky blue Bottom White \033[0m"
Echo-e "\033[47;30m black character \033[0m on white background"
Text color range: 30-37 (color by default, without setting high brightness properties \033[1m)
30: Black 31: Red 32: Green 33:***
34: Blue 35: Purple 36: Cyan 37: White
Echo-e "\033[40;37m Black Bottom White \033[0m"
Echo-e "\033[41;37m Red bottom White \033[0m"
Echo-e "\033[42;37m Green bottom White \033[0m"
Echo-e "\033[43;37m Yellow \033[0m"
Echo-e "\033[44;37m Blue bottom White \033[0m"
Echo-e "\033[45;37m Purple \033[0m"
Echo-e "\033[46;37m sky blue Bottom White \033[0m"
Echo-e "\033[47;30m black character \033[0m on white background"
Text color range: 30-37 (plus set high brightness properties \033[1m)
30: Dark grey 31: Light Red 32: Light green 33:***
34: Light Blue 35: Light Purple 36: Light Cyan 37: White
Control code:
\33[0m Close All Properties
\33[1m Setting High brightness
\33[4m Underline
\33[5m Flashing
\33[7M Reverse Display
\33[8m blanking
\33[30m-\33[37m Setting the foreground color
\33[40m-\33[47m Setting the background color
\33[na the cursor to move n rows
\33[NB cursor down n rows
\33[NC cursor right shifts n rows
\33[nd cursor left n rows
\33[Y;XH Setting the cursor position
\33[2J Clear Screen
\33[k clears the contents from the cursor to the end of the line
\33[s Save Cursor position
\33[u Restore cursor Position
\33[?25l Hide Cursor
\33[?25h Display cursor
This article is from the "Boyhack" blog, make sure to keep this source http://461205160.blog.51cto.com/274918/1949732
Shell Work Note 01