break continue exit
break 结束本次for循环
写个for循环脚本
vim for2.sh
#!/bin/bash ## for i in `seq 1 5` do echo $i if [ $i -eq 4 ] then break fi echo $i done echo "for done"
sh for2.sh
1
1
2
2
3
3
4
for done
continue 结束本次循环
#!/bin/bash ## for i in `seq 1 5` do echo $i if [ $i -eq 4 ] then continue fi echo $i done echo "for done"
1
1
2
2
3
3
4
5
5
for done
exit 结束shell
#!/bin/bash ## for i in `seq 1 10` do echo $i if [ $i -eq 4 ] then exit fi echo $i done echo "for done"
1
1
2
2
3
3
4