echo -e 可以控制字体颜色和背景颜色输出
从一个例子开始:
# echo -e "e[1;33;41m test content e[0m"
输出效果:
1. e 转义起始符,定义一个转义序列, 可以使用 33代替 2. [ 表示开始定义颜色 3. 1表示高亮,33表示字体颜色为黄色,45表示背景色为红色 4. “test content” 属于文字内容 5. m 转义终止符,表示颜色定义完毕 6. 再次使用 e[ ,表示再次开启颜色定义,0表示使用默认的颜色,m表示颜色定义结束,所以 e[0m 的作用是恢复之前的配色方案
一、字体颜色
字体颜色:30——37
默认=0,黑色=30,红色=31,绿色=32,黄色=33,蓝色=34,紫色=35,天蓝色=36,白色=3
[root@k8s-node02 test]# echo -e "e[30m test content黑 e[0m" test content黑 [root@k8s-node02 test]# echo -e "e[31m test content红 e[0m" test content红 [root@k8s-node02 test]# echo -e "e[32m test content绿 e[0m" test content绿 [root@k8s-node02 test]# echo -e "e[33m test content黄 e[0m" test content黄 [root@k8s-node02 test]# echo -e "e[34m test content蓝 e[0m" test content蓝 [root@k8s-node02 test]# echo -e "e[35m test content紫 e[0m" test content紫 [root@k8s-node02 test]# echo -e "e[36m test content天蓝 e[0m" test content天蓝 [root@k8s-node02 test]# echo -e "e[37m test content白 e[0m" test content白
输出效果:
二、字背景颜色
字背景颜色:40——47
默认=0,黑色=40,红色=41,绿色=42,黄色=43,蓝色=44,紫色=45,天蓝色=46,白色=47
[root@k8s-node02 test]# echo -e "e[40m test content黑 e[0m" test content黑 [root@k8s-node02 test]# echo -e "e[41m test content红 e[0m" test content红 [root@k8s-node02 test]# echo -e "e[42m test content绿 e[0m" test content绿 [root@k8s-node02 test]# echo -e "e[43m test content黄 e[0m" test content黄 [root@k8s-node02 test]# echo -e "e[44m test content蓝 e[0m" test content蓝 [root@k8s-node02 test]# echo -e "e[45m test content紫 e[0m" test content紫 [root@k8s-node02 test]# echo -e "e[46m test content天蓝 e[0m" test content天蓝 [root@k8s-node02 test]# echo -e "e[47m test content白 e[0m" test content白
输出效果:
三、黑底彩色
黑底彩色:90——97
黑=90 深红=91 绿=92 黄色=93 蓝色=94 紫色=95 深绿=96 白色=97
[root@k8s-node02 test]# echo -e "e[90m test content黑 e[0m" test content黑 [root@k8s-node02 test]# echo -e "e[91m test content红 e[0m" test content红 [root@k8s-node02 test]# echo -e "e[92m test content绿 e[0m" test content绿 [root@k8s-node02 test]# echo -e "e[93m test content黄 e[0m" test content黄 [root@k8s-node02 test]# echo -e "e[94m test content蓝 e[0m" test content蓝 [root@k8s-node02 test]# echo -e "e[95m test content紫 e[0m" test content紫 [root@k8s-node02 test]# echo -e "e[96m test content天蓝 e[0m" test content天蓝 [root@k8s-node02 test]# echo -e "e[97m test content白 e[0m" test content白
输出结果:
四、字体控制选项: