Shell script break and Continue commands

Source: Internet
Author: User

In the loop, sometimes you need to force out of the loop when the loop end condition is not reached, and the shell uses break and continue to jump out of the loop.

The break command allows you to jump out of all loops (all loops after the execution is terminated).

The continue command does not jump out of all loops, just out of the current loop.

Example of a break command:

#!/bin/Bash forIinch$(seq 1 Ten) Do    if[[$i = =3]]; Then        Echo " Break" BreakElse        Echo "Continue"        Sleep 1    fi Done

Run results

# Bash test. SH Continuecontinuebreak

Examples of continue commands:

 #!/bin/bash  for  i in  $ (seq  1  10  )  do  if  [[$i = = 3 ];        then  echo   " continue   "  continue         else  sleep  1  fi  echo
     $i  done  

Run results

# bash AA. SH 1 2 Continue 4 5 6 7 8 9 Ten

Shell script break and Continue commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.