Shell 编程基础之 Case 练习
生活随笔
收集整理的這篇文章主要介紹了
Shell 编程基础之 Case 练习
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、語法
case $變量 in"第一個變量內容") # 每個變量內容建議用雙引號括起來,關鍵字則為小括號 )# 執行內容;; # 每個類別結尾使用兩個連續的分號來處理!"第二個變量內容")# 執行內容;;*) # 最后一個變量內容都會用 * 來代表所有其他值,但不包含第一個變量內容與第二個變量內容的其他程序運行段# 執行內容;; esac # 最終的以反寫的 case 結尾二、練習
status=0 # 0: start; 1:stop case "$1" in "start")echo "* program is running";; "stop")echo "* Stopping program";; "status")echo "* program is running";; "restart")echo "* Stopping program"echo "* program is running";; *)echo "Plz input [start|stop|status|restart]";; esac user@ae01:~$ ./test.sh start * program is running user@ae01:~$ ./test.sh stop * Stopping program user@ae01:~$ ./test.sh status * program is running user@ae01:~$ ./test.sh restart * Stopping program * program is running user@ae01:~$ ./test.sh Plz input [start|stop|status|restart] user@ae01:~$
?
轉載于:https://www.cnblogs.com/tannerBG/p/4057182.html
總結
以上是生活随笔為你收集整理的Shell 编程基础之 Case 练习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 想念一个人是一种温馨,被别人想念是一种幸
- 下一篇: 表达式计算器类的设计4(面向对象的表达式