首页 > 技术文章 > 通用shell函数库

root0 2018-12-14 18:20 原文

1、输出字体颜色库

#!/bin/bash

export black='\E[0m\c'
export boldred='\E[1;31m\c'
export boldgreen='\E[1;32m\c'
export boldyellow='\E[1;33m\c'
export boldblue='\E[1;34m\c'
export boldmagenta='\E[1;35m\c'
export boldcyan='\E[1;36m\c'

c_notify=$boldgreen   #通过变量来修改颜色
c_error=$boldred

cecho()
{
        message=$1
        color=${2:-$black}

        echo -e "$color"
        echo -e "$message"
        tput sgr0                       # Reset to normal.
        echo -e "$black"
        return
}

cecho "1. #################" $boldred
cecho "2. #################" $boldgreen
cecho "3. #################" $boldyellow
cecho "4. #################" $boldblue
cecho "5. #################" $boldmagenta
cecho "6. #################" $boldcyan

cecho "启动成功" $c_notify 
cecho "启动失败" $c_error

输出效果:

 

推荐阅读