break命令容許跳出全部循環(終止執行後面的全部循環)shell
#!/bin/bash
while :
do
echo -n "輸入 1 到 5 之間的數字:"
read aNum
case $aNum in
1|2|3|4|5) echo "你輸入的數字爲 $aNum!"
;;
*) echo "你輸入的數字不是 1 到 5 之間的! 遊戲結束"
break
;;
esac
donebash
break 實例 2ide
#!/bin/bash
i=1
for day in mon tue wed thu fri
do
echo "Weeking $((i++)) : $day"
if [ $i -eq 3 ];then
break
fi
done遊戲
執行結果it
[root@zabbix shell]# sh break.sh
Weeking 1 : mon
Weeking 2 : tueclass
continue命令與break命令相似,只有一點差異,它不會跳出全部循環,僅僅跳出當前循環。循環
對上面的例子進行修改:di
#!/bin/bash
while :
do
echo -n "輸入 1 到 5 之間的數字: "
read aNum
case $aNum in
1|2|3|4|5) echo "你輸入的數字爲 $aNum!"
;;
*) echo "你輸入的數字不是 1 到 5 之間的!"
continue
echo "遊戲結束"
;;
esac
doneview
contibue 實例2vi
#!/bin/bash
i=1
for day in mon tue wed thu fri sat sun
do
echo -n "Day $((i++)) : $day"
if [ $i -eq 7 -o $i -eq 8 ];then
echo " (WEEKEND)"
continue
fi
echo " (weekday)"
done
執行結果
[root@zabbix shell]# sh break.shDay 1 : mon (weekday)Day 2 : tue (weekday)Day 3 : wed (weekday)Day 4 : thu (weekday)Day 5 : fri (weekday)Day 6 : sat (WEEKEND)Day 7 : sun (WEEKEND)