#!/bin/bash ## test color for script RED_COLOR='\E[1;31m' GREEN_COLOR='\E[1;32m' YELLOR_COLOR='\E[1;33m' BLUE_COLOR='\E[1;34m' PINK='\E[1;35m' RES='\E[0m' if [ $# -eq 2 ] then echo "Usage:`basename $0` content {red|blue|yellow|pink|res|green}" exit 1 fi function echo_color(){ case $2 in red|RED) echo -e "${RED_COLOR}$1${RES}" ;; green|GREEN) echo -e "${GREEN_COLOR$1${RES}}" ;; yellow|YELLOW) echo -e "${YELLOW_COLOR}$1${RES}" ;; BLUE|blue) echo -e "${BLUE_COLOR}$1${RES}" ;; PINK|pink) echo -e "${PINK}$1${RES}" ;; *) echo -e "${PINK}$1${RES}" esac } echo_color abc red echo_color def pink
转载于:https://blog.51cto.com/xiewb/1791780