Exit from a for, while, until, or select loop
break [n]If n is supplied, the nth enclosing loop is exited. n must be greater than or equal to 1.
The return status is zero unless n is not greater than or equal to 1.
for myloop in 1 2 3 4 5
echo -n "$myloop"
if [ "$myloop" -eq 3 ]
break # This line will break out of the loop
donebreak is a POSIX `special'' builtin
About the Author
FortyPoundHead has posted a total of 1974 articles.
Comments On This Post
No comments on this post yet!
Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.
Or you can drop a note to the administrators if you're not sure where you should post.