• shell脚本定义输出字符颜色


    #-------------------定义输入颜色---------------------#
      RED='33[1;31m'
      GREEN='33[1;32m'
      YELLOW='33[1;33m'
      BLUE='33[1;34m'
      NORMAL='33[0m'
      RedBG='33[1;41;37m'
      GreenBG='33[1;42;37m'
      YellowBG='33[1;43;37m'

      Screen=$(stty -F /dev/console size|awk '{print $2}')
    #如果算出来的值为空,就默认赋值为80.
      Columns=${Screen:-80}
    #减12是指减掉"[ $RED File $NORMAL ]"所占的字符.
      SPACOL=$[$Columns-12]

    GreenChar() {
      String=$1
    #计算出真正的空白数,$Columns-12后的结果再减$1的字符数.
      RTSPA=$[${SPACOL}-${#String}]
      echo -en "$GREEN${String}$NORMAL"
      for I in `seq 1 $RTSPA`;do #如果I在1到68,则输出------
    #出输入空白

    #seq 1 $RTSPA的输出结果

    #

        echo -n "-" #echo -n是不输出换行符
      done
      echo -e "[$GREEN OK $NORMAL]" # 输出结果[ OK ],-e允许反斜杠的转义
    }

    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 ]
    }

    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() {

      echo ""
      echo -e "[[ $GreenBG $1 $NORMAL ]]"
      echo ""
    }

    RedBGChar() {

      echo ""
      echo -e "[[ $RedBG $1 $NORMAL ]]"
      echo ""
    }

    YellowBGChar() {

      echo ""
      echo -e "[[ $YellowBG $1 $NORMAL "
      echo ""
    }

    BG的输出结果

    最终的字符效果

  • 相关阅读:
    安卓反编译
    Icesugar Gourd
    php文件写入
    java 序列化与反序列化
    Toj Dominoes Game
    adb&frida
    Markdown 测试用例
    iview InputNumber类输入框表单验证失效
    01背包问题(回溯算法实现)
    阅读作业二读Lost in CatB有感 by 李栋
  • 原文地址:https://www.cnblogs.com/qfdxxdr/p/8550634.html
Copyright © 2020-2023  润新知