if else
if condition1 then command1 elif condition2 then command2 else commandN fi
for循环
for var in item1 item2 ... itemN do command1 command2 ... commandN done #写成一行 for var in item1 item2 ... itemN; do command1; command2… done;
while语句
while condition do command done
until循环
until 循环执行一系列命令直至条件为 true 时停止
until condition do command done
case语句
每个 case 分支用右圆括号开始
用两个分号 ;; 表示 break,即执行结束
esac(就是 case 反过来)作为结束标记
case 值 in 1) command1 command2 ... commandN ;; 2) command1 command2 ... commandN ;; esac
无限循环的几种实现模式
while : do command done while true do command done for (( ; ; ))
跳出循环
break #跳出所有循环(终止执行后面的所有循环) continue #仅仅跳出当前循环