通过传参打印彩色字符串

 

#!/bin/bash
black_color='\E[1;30m'
red_color='\E[1;31m'
green_color='\E[1;32m'
yellow_color='\E[1;33m'
blue_color='\E[1;34m'
purple_color='\E[1;35m'
cyan_color='\E[1;36m'
white_color='\E[1;37m'
RES='\E[0m'
word=$1
colors=$2

case $2 in
     black|BLACK|黑色)
          echo -e "$black_color $word $RES"
          exit 0
     ;;
     red|RED|红色)
          echo -e "$red_color $word $RES"
          exit 0
     ;;
     green|GREEN|绿色)
          echo -e "$green_color $word $RES"
          exit 0
     ;;
     yellow|YELLOW|***)
          echo -e "$yellow_color $word $RES"
          exit 0
     ;;
     blue|BLUE|蓝色)
          echo -e "$blue_color $word $RES"
          exit 0
     ;;
     purple|PURPLE|紫色)
          echo -e "$purple_color $word $RES"
          exit 0
     ;;
     cyan|CYAN|青色)
          echo -e "$cyan_color $word $RES"
          exit 0
     ;;
     white|WHITE|白色)
          echo -e "$white_color $word $RES"
          exit 0
     ;;
     *)
          echo "Usage: bash $0 word color."
     ;;

esac

你可能感兴趣的:(字符串,black)