There are two ways to let echo output a color
1. Define the color variable in the shell script and use ECHO-E to invoke the variable
2. When defining variables, define the ECHO-E into a variable, and then output the variable
Shell script that allows echo to display colors
#!/bin/bash
#定义颜色的变量
Red_color= ' \e[1;31m ' #红
Green_color= ' \e[1;32m ' #绿
Yelow_color= ' \e[1;33m ' #黄
Blue_color= ' \e[1;34m ' #蓝
pink= ' \e[1;35m ' #粉红
res= ' \e[0m '
#需要使用echo-E
Echo-e "${red_color}======red Color======${res}"
Echo-e "${yelow_color}======yelow Color======${res}"
Echo-e "${blue_color}======green Color======${res}"
Echo-e "${green_color}======green Color======${res}"
Echo-e "${pink}======pink Color======${res}"
echo "#############################################################"
#直接把echo-E is placed in the variable, directly output the variable when used
setcolor_success= "Echo-en \\033[1;32m"
Setcolor_failure= "Echo-en \\033[1;31m"
setcolor_warning= "Echo-en \\033[1;33m"
Setcolor_normal= "Echo-en \\033[0;39m"
echo----Oldboy trainning-----&& $SETCOLOR _success
echo----Oldboy trainning-----&& $SETCOLOR _failure
echo----Oldboy trainning-----&& $SETCOLOR _warning
echo----Oldboy trainning-----&& $SETCOLOR _normal
Script execution results are as follows