标签:关闭 \e[0m $1 else nginx val cas ice action
case 条件语句语法
case 条件语句语法格式为:
case " 变量 " in
值 1)
指令 1
;;
值 2)
指令 2
;;
\* )
指令 3
;;
esac
了解即可
给字体加颜色的命令:
例:echo -e "\E[1;31m 红颜色 hello world \E[0m"
#!/bin/bash
RETVAL=0
pid=/var/run/nginx.pid
. /etc/init.d/functions
start(){
if [ ! -f $pid ];then
service nginx start
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "nginx is started" /bin/true
return $RETVAL
else
action "nginx is started" /bin/false
return $RETVAL
fi
else
echo "nginx is running"
return 0
fi
}
stop(){
if [ -f $pid ];then
service nginx stop
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "nginx is started" /bin/true
return $RETVAL
else
action "nginx is started" /bin/false
return $RETVAL
fi
else
echo "nginx is stop"
return 0
fi
}
restart(){
stop
start
}
case $1 in
start|yes)
start
RETVAL=$?
;;
stop|no)
stop
RETVAL=$?
;;
restart|or)
restart
RETVAL=$?
;;
\*)
echo "Usage:$0{start(yse)|stop(on)|restart(or)}"
exit 1
esac
exit $RETVAL
标签:关闭 \e[0m $1 else nginx val cas ice action
原文地址:http://blog.51cto.com/12384628/2294211