shell脚本编程之for语句、if语句使用介绍

2019-09-23 09:45:32于海丽

如果参数为status,那么:
如果/var/lock/subsys/script文件存在,则显示为“script is running.”
否则,则显示为“script is stopped.”
其它任何参数:则显示“script.sh {start|stop|restart|status}”


#!/bin/bash
if [ $1 == start ] ;then
   touch /var/lock/subsys/script
   echo "Starting script successfully."
 elif [ $1 == stop ] ; then
    rm -f /var/louk/subsys/script
    echo "Stop script finished."
 elif [ $1 == restart ];then
     rm -f /var/louk/subsys/script
     touch  /var/lock/subsys/script
    echo "Restarting script successfully."
  elif [ $1 == status ];then
     [ -e /var/lock/subsys/script ]&& echo "script is running." || echo "script is stopped."
 else
   echo "script.sh {start|stop|restart|status}"
fi