#-------------------定義輸入顏色---------------------#
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NORMAL='\033[0m'
RedBG='\033[1;41;37m'
GreenBG='\033[1;42;37m'
YellowBG='\033[1;43;37m'spa
Screen=$(stty -F /dev/console size|awk '{print $2}')
#若是算出來的值爲空,就默認賦值爲80.
Columns=${Screen:-80}
#減12是指減掉"[ $RED File $NORMAL ]"所佔的字符.
SPACOL=$[$Columns-12]blog
GreenChar() {
String=$1
#計算出真正的空白數,$Columns-12後的結果再減$1的字符數.
RTSPA=$[${SPACOL}-${#String}]
echo -en "$GREEN${String}$NORMAL"
for I in `seq 1 $RTSPA`;do #若是I在1到68,則輸出------
#出輸入空白 console
#seq 1 $RTSPA的輸出結果awk
#im
echo -n "-" #echo -n是不輸出換行符
done
echo -e "[$GREEN OK $NORMAL]" # 輸出結果[ OK ],-e容許反斜槓\的轉義
}img
RedChar() {
String=$1
RTSPA=$[${SPACOL}-${#String}]
echo -en "$RED${String}$NORMAL"
for I in `seq 1 $RTSPA`;do
echo -n "-"
done
echo -e "[$RED Failed $NORMAL]" #同理,一行的最後字符是[ Failed ]
}co
YellowChar() {
String=$1
RTSPA=$[${SPACOL}-${#String}]
echo -en "$YELLOW${String}$NORMAL"
for I in `seq 1 $RTSPA`;do
echo -n "-"
done
echo -e "[$YELLOW Warning $NORMAL]" #同理,一行的最後字符是[ Warning ]
}字符
GreenBGChar() {background
echo ""
echo -e "[[ $GreenBG $1 $NORMAL ]]"
echo ""
}ps
RedBGChar() {
echo ""
echo -e "[[ $RedBG $1 $NORMAL ]]"
echo ""
}
YellowBGChar() {
echo ""
echo -e "[[ $YellowBG $1 $NORMAL "
echo ""
}
BG的輸出結果
最終的字符效果