例子:
powershell
~ script % vim while.sh
~ script % ./while.sh
powershell
#!/usr/bin/env bash
COUNT=0
while [ $COUNT -lt 10 ]
do
echo "Count # $COUNT"
((COUNT++))
done
exit 0
powershell
script % ./while.sh
Count # 0
Count # 1
Count # 2
Count # 3
Count # 4
Count # 5
Count # 6
Count # 7
Count # 8
Count # 9
语法:
powershell
while [ 循环条件 ]
do
循环体
done
或
powershell
while test 循环条件
do
循环体
done
while循环还是比较简单的。