shell echo颜色例子

#!/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

posted @ 2016-04-18 14:12  xiewb  阅读(215)  评论(0编辑  收藏  举报