写法 1
function echo_color(){
if [ $1 == "green" ]; then
echo -e "\033[32;40m$2\033[0m"
elif [ $1 == "red" ]; then
echo -e "\033[31;40m$2\033[0m"
fi
}
echo_color green "我是绿色"
echo_color red "我是红色"
写法 2 也可以在前面不写function,也可以定义函数
echo_color(){
case $1 in
green)
echo -e "\033[32;40m$2\033[0m"
;;
red)
echo -e "\033[31;40m$2\033[0m"
;;
*)
echo "Example: echo_color red string"
esac
}
echo_color green "我是绿色"
更多建站及源码交易信息请见 GoodMai 好买网www.goodmai.com