if...else
if [ $1x == "ab"x ]; then echo "you had enter ab" elif [ $1x == "cd"x ]; then echo "you had enter cd" else echo "you had enter unexpected word" fi
case...esac
类似于其他语言的 switch case,但是,这里的 case 子句可以匹配多种情况,每个 case 子句后面需要有独立的一行 ";"
#!/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 done