shell脚本之break跳出循环 continue结束本次循环

#!/bin/bash
for i in seq 1 5
do
echo $i
if [ $i -eq 3 ] #对数字进行比较用eq,字符串用==
then
break #当i等于3时,就跳出循环
fi
echo $i
done
echo NBA

[root@allen shell]# sh break.sh
1
1
2
2
3
NBA

#!/bin/bash
for i in seq 1 5
do
echo $i
if [ $i -eq 3 ]
then
continue
fi
echo $i
done
echo NBA

[root@allen shell]# sh continue.sh
1
1
2
2
3
4
4
5
5
NBA

你可能感兴趣的:(shell)