让shell脚本中的echo输出带颜色
2017-09-19 22:21
218 查看
转载自:http://www.linuxidc.com/Linux/2014-12/110463.htm
让echo输出带颜色的方法有两种
1.在shell脚本中定义颜色变量,使用echo -e调用变量
2.定义变量的时候,把echo -e定义到变量中,然后输出变量
可以让echo输出显示颜色的shell脚本
#!/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放到变量里面,使用的时候直接输出变量即可
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
脚本执行结果如下
让echo输出带颜色的方法有两种
1.在shell脚本中定义颜色变量,使用echo -e调用变量
2.定义变量的时候,把echo -e定义到变量中,然后输出变量
可以让echo输出显示颜色的shell脚本
#!/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放到变量里面,使用的时候直接输出变量即可
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
脚本执行结果如下
相关文章推荐
- 让shell脚本中的echo输出带颜色
- shell脚本中echo带颜色输出
- 让shell脚本中的echo输出带颜色
- 让shell脚本中的echo输出带颜色
- 让shell脚本中的echo输出带颜色
- SHELL脚本的echo输出颜色
- 让shell脚本中的echo输出带颜色
- shell脚本中echo显示内容带颜色显示
- shell脚本中echo打印带颜色
- Linux下Shell脚本输出带颜色文字
- shell脚本中echo显示内容带颜色
- 设置shell脚本输出字体颜色
- shell脚本中echo显示内容带颜色的实现方法
- shell脚本:shell的基本元素-3 简单的echo输出
- shell脚本中echo显示内容带颜色
- shell脚本中echo显示内容带颜色 【常用】
- shell脚本echo输出不换行功能增强实例
- shell脚本中echo显示内容带颜色
- shell脚本中echo显示内容带颜色
- shell脚本中echo显示内容带颜色