case 條件語句語法
case 條件語句語法格式爲:nginx
case " 變量 " in 值 1) 指令 1 ;; 值 2) 指令 2 ;; \* ) 指令 3 ;; esac
瞭解便可
給字體加顏色的命令:
例:echo -e "\E[1;31m 紅顏色 hello world \E[0m"bash
#!/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