Linux 中 echo 命令 将字体输出颜色

发布时间 2023-11-15 23:37:45作者: 小鲨鱼2018

 

001、示例

(base) [root@pc1 test]# echo -e "\033[47;30m xxxxx \033[0m"   ## 47 表示背景色;30表示字体颜色
 xxxxx

 

002、取消背景色

(base) [root@pc1 test]# echo -e "\033[30m xxxxx \033[0m"       ## 取消背景色, 字体为黑色
 xxxxx
(base) [root@pc1 test]# echo -e "\033[31m xxxxx \033[0m"       ## 取消背景色, 字体为红色
 xxxxx

 

003、输出绿色字

(base) [root@pc1 test]# echo -e "\033[32m xxxxx \033[0m"
 xxxxx

 

004、其他字体颜色

(base) [root@pc1 test]# echo -e "\033[33m xxxx \033[0m"        ## 黄色字体
 xxxx
(base) [root@pc1 test]# echo -e "\033[34m yyyy \033[0m"        ## 蓝色字体
 yyyy
(base) [root@pc1 test]# echo -e "\033[35m aaaa \033[0m"        ## 紫色字体 
 aaaa
(base) [root@pc1 test]# echo -e "\033[36m xxxx \033[0m"        ## 亮蓝色字体
 xxxx
(base) [root@pc1 test]# echo -e "\033[37m xxxx \033[0m"        ## 白色字体
 xxxx

 

005、背景和字体颜色组合

(base) [root@pc1 test]# echo -e "\033[40;37m xxxx \033[0m"        ## 黑底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[41;37m xxxx \033[0m"        ## 红底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[42;37m xxxx \033[0m"        ## 绿底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[43;37m xxxx \033[0m"        ## 黄底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[44;37m xxxx \033[0m"        ## 蓝底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[45;37m xxxx \033[0m"        ## 紫底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[46;37m xxxx \033[0m"        ## 亮蓝底白字
 xxxx
(base) [root@pc1 test]# echo -e "\033[47;30m xxxx \033[0m"        ## 白底黑字
 xxxx

 。

 

参考:

01、https://blog.csdn.net/qq_33023953/article/details/130834772