Detailed explanation of the color and format of the output in the shell bash terminal (super detailed)
In a Bash terminal, you can use ANSI escape sequences to control the color and format of the output. These sequences start with "\e[", end with "m", and contain one or more digits, separated by semicolons.
Here are some ANSI escape sequences and their corresponding colors and formats:
color:
- \e[30m : black
- \e[31m : red
- \e[32m : green
- \e[33m : yellow
- \e[34m : blue
- \e[35m : purple
- \e[36m : cyan
- \e[37m : white
background color:
- \e[40m : black
- \e[41m : red
- \e[42m : green
- \e[43m : yellow
- \e[44m : blue
- \e[45m : purple
- \e[46m : cyan
- \e[47m : white
Format:
- \e[0m : reset all formatting
- \e[1m : bold
- \e[2m : fade
- \e[3m : italics
- \e[4m : underscore
- \e[5m : blink
- \e[7m : reverse display
- \e[8m : hide
- \e[9m : strike out
- \e[21m : cancel bold
- \e[22m : cancel fade
- \e[23m : remove italics
- \e[24m : cancel underline
- \e[25m : cancel flashing
- \e[27m : Cancel reverse display
- \e[29m : cancel strikeout
Usage:
connect the above characters with the content to be output, for example:
- echo -e "\e[31m this is red text\e[0m": output red text
- echo -e "\e[1m this is bold text\e[0m": output bold text
- echo -e "\e[41m this is a red background\e[0m" : output a red background
Notice:
- To use ANSI escape sequences in the Bash terminal, you need to use the -e option, for example: echo -e "\e[31m this is the red text \e[0m"
- Some terminals may not support all colors and formats, so the output may vary.
- When using color and formatting, you should be careful not to overdo it so that it affects readability.
For a more detailed description, please refer to the following website
https://www.cnblogs.com/unclemac/p/12783387.html