江苏体育建设场地网站,青岛网站建设哪个平台好,上海传媒公司排行榜,专业网站设计流程图Background 在编写比较复杂的脚本时#xff0c;需要输出相关日志信息#xff0c;方便知悉脚本的执行情况以及问题的排查。 源码 log.sh
# 自定义日志函数
function log(){if [[ $1 i || $1 info ]]; thenecho -ne \033[1;34mINFO: \033[0m需要输出相关日志信息方便知悉脚本的执行情况以及问题的排查。 源码 log.sh
# 自定义日志函数
function log(){if [[ $1 i || $1 info ]]; thenecho -ne \033[1;34mINFO: \033[0mshift echo -e $elif [[ $1 w || $1 warn ]]; thenecho -ne \033[1;33mWARN: \033[0mshift echo -e $elif [[ $1 s || $1 success ]]; thenecho -ne \033[1;32mSUCCESS: \033[0mshift echo -e $elif [[ $1 e || $1 error ]]; thenecho -ne \033[1;31mERROR: \033[0mshift echo -e $elsecolors$1input$2opt-erightpatterntrueif [[ ${colors:0:1} n ]]; thencolors${colors//n/}opt-nefiif [[ $colors ~ , ]]; thencolorarr${colors//,/ }colors${colors//,/;}for color in ${colorarr[]};doif ! [[ $color ~ ^[0-9]$ $color -gt 0 $color -lt 49 ]]; thenrightpatternfalsefidoneelseif ! [[ $colors ~ ^[0-9]$ $colors -gt 0 $colors -lt 49 ]]; thenrightpatternfalsefifiif [[ -n $input $rightpattern true ]]; thenshift str$echo $opt \033[${colors}m${str}\033[0melsestr$echo $opt ${str}fifi
}log $使用
输出i-提示、w-告警、s-成功和e-错误信息
sh log.sh i wlf is a coder
sh log.sh w wlf is a coder
sh log.sh s wlf is a coder
sh log.sh e wlf is a coder直接输出字符串和echo功能一样
sh log.sh wlf is a coder
sh log.sh wlf is a coder输入参数第一个字符为n则不换行输出相当于echo -n
sh log.sh nwlf is a coder输入字体设置序号设置输出字体
sh log.sh 33 wlf is a coder
sh log.sh n33 wlf is a coder
sh log.sh 333 wlf is a coder多种格式英文分号,分隔
sh log.sh 4,33 wlf is a coder
sh log.sh n4,33 wlf is a coder
sh log.sh 4,333 wlf is a coder字体设置表
序号设置0重新设置属性到缺省设置1设置粗体2设置一半亮度(模拟彩色显示器的颜色)4设置下划线(模拟彩色显示器的颜色)5设置闪烁7设置反向图象22设置一般密度24关闭下划线25关闭闪烁27关闭反向图象30设置黑色前景31设置红色前景32设置绿色前景33设置棕色前景34设置蓝色前景35设置紫色前景36设置青色前景37设置白色前景38在缺省的前景颜色上设置下划线39在缺省的前景颜色上关闭下划线40设置黑色背景41设置红色背景42设置绿色背景43设置棕色背景44设置蓝色背景45设置紫色背景46设置青色背景47设置白色背景49设置缺省黑色背景