searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

Shell脚本输出带颜色的内容

2023-06-07 10:10:59
31
0

颜色参数定义

颜色 前景色 背景色
黑色(block) 30 40
红色(red) 31 41
绿色(green) 32 42
黄色(yellow) 33 43
蓝色(blue) 34 44
紫红色(magenta) 35 45
青色(cyan) 36 46
白色(white) 37 47

 

1.红色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[41;30m red background \033[0m"
 red background 

2.绿色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[42;30m green background \033[0m"
 green background 

3.黄色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[43;30m yello background \033[0m"
 yello background 

4.黑色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[30m black \033[0m"
 black 

5.黑色底,红色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[31m red \033[0m"
 red 

6.黑色底,绿色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[32m green \033[0m"
 green 

7.黑色底,黄色字
[root@shxxy-jumpserver1-10e255e251e248 ~]#  echo -e "\033[33m yellow \033[0m"
 yellow 

8.黑色底,白色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[46:30m white \033[0m"
 white 

9.黑色底,红色字,加红色下划线
[root@shxxy-jumpserver1-10e255e251e248 ~]#  echo -e "\033[4;31m underline red \033[0m"
 underline red 

10.黑色底,绿色字,加绿色下划线
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[4;32m underline green \033[0m"
 underline green 

11.黑色底,黄色字,加黄色下划线
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[4;33m underline yellow \033[0m"
 underline yellow 


12.黑色底,红色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;31m twinkle red \033[0m"
 twinkle red 

13.黑色底,绿色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;32m twinkle green \033[0m"
 twinkle green 

14.黑色底,黄色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;33m twinkle yellow \033[0m"
 twinkle yellow 

15.黑色底,蓝色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;34m twinkle blue \033[0m"
 twinkle blue 

16.黑色底,粉色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;35m twinkle pink \033[0m"
 twinkle pink 

17.黑色底,青色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;36m twinkle cyan \033[0m"
 twinkle cyan 

18.黑色底,青色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\E[5;36m twinkle cyan \E[0m"
 twinkle cyan 

脚本例子:
[root@YTJ-10e101e8e11 ~]# cat test.sh 
RED='\E[1;31m'
GREEN='\E[1;32m'
YELLOW='\E[1;33m'
BLUE='\E[1;34m'
PINK='\E[1;35m'
RES='\E[0m'

echo -e "$RED====red color===$RES"
echo -e "$GREEN====green color===$RES"
echo -e "$YELLOW====yellow color===$RES"
echo -e "$BLUE====blue color===$RES"
echo -e "$PINK====pink color===$RES"

SUCCESS="echo -en \\033[1;32m"
FAILURE="echo -en \\033[1;31m"
WARNING="echo -en \\033[1;33m"
NORMAM="echo -en \\033[1;39m"

echo ---success--- && $SUCCESS
echo ---failure--- && $FAILURE
echo ---warning--- && $WARNING
echo ---normal--- && $NORMAL
echo -ne $RES
[root@YTJ-10e101e8e11 ~]# bash test.sh 
====red color===
====green color===
====yellow color===
====blue color===
====pink color===
---success---
---failure---
---warning---
---normal---

输出结果如下:

0条评论
作者已关闭评论
c****n
2文章数
0粉丝数
c****n
2 文章 | 0 粉丝
c****n
2文章数
0粉丝数
c****n
2 文章 | 0 粉丝
原创

Shell脚本输出带颜色的内容

2023-06-07 10:10:59
31
0

颜色参数定义

颜色 前景色 背景色
黑色(block) 30 40
红色(red) 31 41
绿色(green) 32 42
黄色(yellow) 33 43
蓝色(blue) 34 44
紫红色(magenta) 35 45
青色(cyan) 36 46
白色(white) 37 47

 

1.红色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[41;30m red background \033[0m"
 red background 

2.绿色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[42;30m green background \033[0m"
 green background 

3.黄色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[43;30m yello background \033[0m"
 yello background 

4.黑色底,黑色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[30m black \033[0m"
 black 

5.黑色底,红色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[31m red \033[0m"
 red 

6.黑色底,绿色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[32m green \033[0m"
 green 

7.黑色底,黄色字
[root@shxxy-jumpserver1-10e255e251e248 ~]#  echo -e "\033[33m yellow \033[0m"
 yellow 

8.黑色底,白色字
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[46:30m white \033[0m"
 white 

9.黑色底,红色字,加红色下划线
[root@shxxy-jumpserver1-10e255e251e248 ~]#  echo -e "\033[4;31m underline red \033[0m"
 underline red 

10.黑色底,绿色字,加绿色下划线
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[4;32m underline green \033[0m"
 underline green 

11.黑色底,黄色字,加黄色下划线
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[4;33m underline yellow \033[0m"
 underline yellow 


12.黑色底,红色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;31m twinkle red \033[0m"
 twinkle red 

13.黑色底,绿色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;32m twinkle green \033[0m"
 twinkle green 

14.黑色底,黄色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;33m twinkle yellow \033[0m"
 twinkle yellow 

15.黑色底,蓝色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;34m twinkle blue \033[0m"
 twinkle blue 

16.黑色底,粉色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;35m twinkle pink \033[0m"
 twinkle pink 

17.黑色底,青色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\033[5;36m twinkle cyan \033[0m"
 twinkle cyan 

18.黑色底,青色字,字闪烁
[root@shxxy-jumpserver1-10e255e251e248 ~]# echo -e "\E[5;36m twinkle cyan \E[0m"
 twinkle cyan 

脚本例子:
[root@YTJ-10e101e8e11 ~]# cat test.sh 
RED='\E[1;31m'
GREEN='\E[1;32m'
YELLOW='\E[1;33m'
BLUE='\E[1;34m'
PINK='\E[1;35m'
RES='\E[0m'

echo -e "$RED====red color===$RES"
echo -e "$GREEN====green color===$RES"
echo -e "$YELLOW====yellow color===$RES"
echo -e "$BLUE====blue color===$RES"
echo -e "$PINK====pink color===$RES"

SUCCESS="echo -en \\033[1;32m"
FAILURE="echo -en \\033[1;31m"
WARNING="echo -en \\033[1;33m"
NORMAM="echo -en \\033[1;39m"

echo ---success--- && $SUCCESS
echo ---failure--- && $FAILURE
echo ---warning--- && $WARNING
echo ---normal--- && $NORMAL
echo -ne $RES
[root@YTJ-10e101e8e11 ~]# bash test.sh 
====red color===
====green color===
====yellow color===
====blue color===
====pink color===
---success---
---failure---
---warning---
---normal---

输出结果如下:

文章来自个人专栏
文章 | 订阅
0条评论
作者已关闭评论
作者已关闭评论
0
0