until循环在条件为假的情况下才会持续地运行。一旦条件被满足,就会退出循环。
until [ CONDITION ]
do
command1
command2
...
command
done
until循环的实例
var=1
until [ $var -gt 3]
do
echo "The for loop is run $var times."
var=$(( var + 1 ))
done
break语句用于从for,while,until,select循环中退出,停止循环的执行。
break [n]
n代表嵌套循环的层级,如果指定了n,break将退出n级嵌套循环。如果没有指定n或n不大于等于1,则退出状态码为0,否则退出状态码为n,脚本实例:
#如果未指定参数,则打印脚本的使用方法,并返回退出状态码1
[ $# -eq 0 ] && { echo "Usage: $0 filepath"; exit 1; }
match=$1
found=0
for file in /etc/*
do
if [ $file == "$match" ]
then
echo "The file $match was found!"
found=1
break
fi
done
[ $found -ne 1 ] && echo "The file $match is not found in /etc dir"
网友评论