Linux Shell 語法日誌

shell 語法很容易忘記 平時開發中很少用 所以記下來以便偶爾使用

case語句

syntax error: unexpected end of file 錯誤是沒有語句結束 比如沒有結束case語句 最有沒有輸入 esac 就會出現此問題

#!/bin/bash
case $1 in 	#$1是獲取控制檯中shell文件後第一個參數;如 sh test.sh start
start)  #判斷是否爲 start 如果寫出[start]) 意爲start中任意一個字符做匹配
echo start tomcat!  #匹配成功後的代碼段
;;
stop)
echo stop tomcat!
;;
restart)
echo restart tomcat!
;;
*)  #默認情況
echo 11111
;;
esac#結束語句
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章