case结构条件语句

语法

case “字符串变量” in
  值 1)
        指令1
		;;
值 2) 
      指令2
		;;
值 n) 
	  指令n
		;;
*) 
	  指令
esac

编写apache启动脚本

#!/bin/bash
# chkconfig:  345 80 10  #345表示在什么级别上启动 80启动优先级  10关闭优先级
# description:    描述信息 
httpd="/application/apache/bin/httpd -k"
. /etc/init.d/functions

case "$1" in
    start)
      $httpd start >/dev/null
      [ $? -eq 0 ] && action "httpd is started" /bin/true||\
       action "httpd is started" /bin/false
    		 ;;
     stop)
       $httpd stop >/dev/null
      [ $? -eq 0 ] && action "httpd is stop" /bin/true||\
       action "httpd is stop" /bin/false
    		 ;;
     restart)
       $httpd restart >/dev/null
      [ $? -eq 0 ] && action "httpd is restarted" /bin/true||\
       action "httpd is restarted" /bin/false
    		 ;;
     *)
       echo "Usage:$0 {start|stop|restart}"
       exit
     		 ;;
esac

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/110187707