Shell Programming-Statements (vii)

Source: Internet
Author: User
Tags closing tag

If Else judgment statement
  If statement
Syntax Format 1:

if condition then statement 1 Statement 2  ... Statement NFI

Syntax Format 2:
Often used in terminal command prompt

 if [conditional];then statement; fi

  If Else statement
Syntax format:

if condition then statement 1 Statement 2  ... Statement nelse  statement fi

  If else-if Else statement
Syntax format:

if condition 1then Statement 1elif condition 2then Statement 2 Else Statement NFI

For Loop statement
Syntax Format 1:

 for inch value 1 Value 2 ... Value n do statement 1 Statement 2 ... Statement Ndone

Syntax Format 2:
Often used in terminal command prompt

 for  in value 1 value 2 ... Value n; do statement 1; statement 2 ... done;

For Dead Loop
Syntax format:

 for ((;;))

While Loop statement
Used to continuously execute a series of commands.
Syntax format:

 while conditions  Do Statement Done

While Dead loop
Syntax Format 1:

 while :  Do Statement Done

Syntax Format 2:

 while true  Do Statement Done

Until cycle
Similar to the while loop, except that while the value is true to continue execution, until is the value of false continuation.
Syntax format:

until conditions  Do Statement Done

Case Selection Statement
The case value must be followed by in, and each pattern must end with a closing parenthesis. After a match discovery value conforms to a pattern, all commands begin to execute until they are encountered;; End.
If there is no matching pattern, use an asterisk * to capture the value and then execute the subsequent command.
Syntax format:

 Case inch mode 1) Statement 1 ... statement n;; mode 2) Statement 1 ... Statement N;;esac

The syntax of a case requires a ESAC (which is case in turn) as the closing tag, with a closing parenthesis for each case branch, and a break with two semicolons

Break command
The break command is to jump out of all loops and terminate all subsequent loops

Continue command
The continue command jumps out of the current loop, but does not jump out of all loops, just jumps out of the current loop, and executes the next loop

Shell Programming-Statements (vii)

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.