linux中 case $1 in start start ;; stop stop ;; restart stop sleep 2 start ;; echo The commant must be start、stop or restart!
这段代码是一个 shell 脚本中的 case 语句,用于根据传入的参数 $1 来执行不同的操作。其中:
- case "$1" in 表示开始 case 语句,$1 是要匹配的参数;
- start) 表示如果 $1 等于 start,则执行后面的 start 命令;
- stop) 表示如果 $1 等于 stop,则执行后面的 stop 命令;
- restart) 表示如果 $1 等于 restart,则先执行后面的 stop 命令,等待 2 秒后再执行 start 命令;
- *) 表示如果 $1 不等于以上三种情况,则执行后面的提示语句;
- esac 表示结束 case 语句。
原文地址: https://www.cveoy.top/t/topic/bqFD 著作权归作者所有。请勿转载和采集!