最典型的shell case命令匹配命令行,啟動腳本的start|stop|restart|status處理
case "$@" in
($@ 字符串數(shù)組:以"參數(shù)1" "參數(shù)2" ... 的字符串數(shù)組形式保存所有參數(shù)
對于單個參數(shù)的情況,$@就一個字符串)
start)
echo -n "Starting firewall..."
。。。
echo "OK!"
exit 0
;;
stop)
echo -n "Stopping firewall..."
。。。
exit 0
;;
restart)
$0 stop $0即執(zhí)行原始程序
$0 start
;;
status)
clear
echo ">------------------------------------------"
iptables -L
echo ">------------------------------------------"
iptables -t nat -L POSTROUTING
exit 0
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac