91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

shell腳本基礎知識梳理<五>:流程控制case

發布時間:2020-07-12 17:39:52 來源:網絡 閱讀:179 作者:wx5cb5dcd871bbc 欄目:系統運維

case使用格式

case 值 in
模式1)
指令1
指令2
...
;;
模式2)
指令1
指令2
...
;;
esca
echo '輸入 1 到 4 之間的數字:'
echo '你輸入的數字為:'
read aNum
case $aNum in
1) echo '你選擇了 1'
;;
2) echo '你選擇了 2'
;;
3) echo '你選擇了 3'
;;
4) echo '你選擇了 4'
;;
*) echo '你沒有輸入 1 到 4 之間的數字'
;;
esac

實例 1

#!/bin/bash
#case...esac
echo "What is your preferred scripting language?"
echo "1) bash"
echo "2) prel"
echo "3) python"
echo "4) ruby"
echo "5) I do not know !"
read lang
case $lang in
1) echo "you selected bash" ;;
2) echo "you selected prel" ;;
3)
echo "you selected python"
;;
4)
echo "you selected ruby"
;;
5)
echo "I do not know!"
;;
esac

執行結果

[root@localhost shell]# sh case.sh
What is your preferred scripting language?
1) bash
2) prel
3) python
4) ruby
5) I do not know !
4
you selected ruby
[root@localhost shell]# sh case.sh
What is your preferred scripting language?
1) bash
2) prel
3) python
4) ruby
5) I do not know !
5
I do not know!
[root@localhost shell]#

實例 2

#!/bin/bash
echo -n "Do you agree whith this? [yes or no]: "
read yn
case $yn in
[Yy] | [Yy][Ee][Ss])
echo "Agreed."
;;
[Nn] | [Nn][Oo])
echo "Not Agreed."
exit 1
;;
*)
echo "Invalid input."
;;
esac

運行結果:

[root@localhost shell]# sh case2.sh
Do you agree whith this? [yes or no]: 1
Invalid input.
[root@localhost shell]# sh case2.sh
Do you agree whith this? [yes or no]: n
Not Agreed.
[root@localhost shell]# sh case2.sh
Do you agree whith this? [yes or no]: Yes
Agreed.
[root@localhost shell]#

實例 3

#!/bin/bash
case $1 in
sql) echo "Runing mysql backup using mysqldump tool..."
;;
sync) echo "Runing backup using rsyuc tool..."
;;
git) echo "Runing backup using gistore tool..."
;;
tar) echo "Runing tape backup using tar tool..."
;;
*)
echo "Backup shell script utility"
echo "Usage: $0 {sql|sync|git|tar}"
echo " sql : Run mysql backup utility."
echo " sync : Run web backup utility."
echo " git : Run gistore backup utility."
echo " tar : Run tape backup utility."
;;
esac

運行結果:

[root@localhost shell]# sh case3.sh
Backup shell script utility
Usage: case3.sh {sql|sync|git|tar}
sql : Run mysql backup utility.
sync : Run web backup utility.
git : Run gistore backup utility.
tar : Run tape backup utility.
[root@localhost shell]# sh case3.sh sql
Runing mysql backup using mysqldump tool...
[root@localhost shell]#

實例 4

#!/bin/bash
#得到磁盤使用率最高的
max_usage=$(df -Ph |awk '{print $5}'|grep %|grep -v "Use"|sort -n|tail -1|cut -d "%" -f1)
max_dir=df -Ph | awk '{print $5,$6}'|grep -v Use|sort -n|tail -1|awk '{print $2}'
case ${max_usage} in
[1-6])
MSG="All is quiet.\"${max_dir}\" is ${max_usage}% used"
;;
[7-8]
)
MSG="Start thinking about cleaning out some stuff. "
MSG="$MSG There's a partition ${max_dir} is ${max_usage}% used."
;;
9[1-8])
MSG="Better hurry with that new disk... "
MSG="$MSG One partition ${max_dir} is ${max_usage}% used."
;;
99)
MSG="I'm drowning herel There's a partiton at ${max_usage}% used"
;;
)
MSG="I seem to be runing with an nonexitent amount of disk space..."
;;
esac
#echo $MSG| mail -s "disk report date" root
echo $MSG

運行結果:

[root@localhost shell]# sh case4.sh
All is quiet."/" is 22% used
[root@localhost shell]#

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

镇平县| 合阳县| 孟津县| 南陵县| 阿荣旗| 泰和县| 油尖旺区| 哈巴河县| 安泽县| 侯马市| 乾安县| 武宣县| 育儿| 焦作市| 法库县| 晋宁县| 白城市| 榆社县| 南城县| 肥乡县| 浦城县| 乐清市| 锡林浩特市| 尚志市| 东阿县| 正阳县| 浪卡子县| 延吉市| 贺州市| 卢龙县| 砀山县| 荥阳市| 汉寿县| 弋阳县| 逊克县| 新泰市| 西乌珠穆沁旗| 阿城市| 嘉黎县| 德庆县| 武邑县|