- if 语句
if condition1
then
command1
elif condition2
then
command2
else
command3
fi
- for 语句
for var in item1, item2, ..., itemN
do
command1
command2
...
commandN
done
- while 语句
while condition
do
command
done
- 无限循环的两个写法
while true
do
command
done
for (( ; ; ))
- until 语句
a=0
until condition
do
command
done
- case 语句
case val in
val1)
command11
command12
;;
val2)
command21
command22
;;
esac
- break/continue 语句
#!/bin/bash
while:
do
echo -n "输入 1 到 5 之间的数字: "
read aNum
case $aNum in
1|2|3|4|5) echo "你输入的数字为 $aNum!"
;;
6|7|8|9|10) echo "你输入的数字为 $aNum!"
break
;;
*) echo "你输入的数字不是 1 到 5 之间的!"
continue
echo "游戏结束"
;;
6
esac
done