shell中的continue和break和其他语言中的使用方法一模一样:continue用于跳过本次循环,break用于中断本层的循环
下面是使用例子:
#!/bin/bash
#文件名:test.sh
for i in 1 2 3 4 5 6 7 8 9
do
if [ $i -eq 4 ]
then
continue
else
echo $i
fi
if [ $i -eq 6 ]
then
break
fi
done
运行:
ubuntu@ubuntu:~$ ./test.sh 1 2 3 5 6 ubuntu@ubuntu:~$