Shell programming If syntax, case syntax, while statement, until statement, for statement, select statement

Source: Internet
Author: User

Mainly introduces the syntax of Shell Basic statement

If statement syntax
1 single branch structure (if, then)
If < condition test >; then instruction; fi
Or as follows:
If < condition testing >
? Then
? Instructions
Fi

2 Dual-branch structure (if, then, otherwise ...) )

If < conditional expressions >
? Then
? Instructions
Else
? Instructions
Fi

Multi-branched structure (if, then, otherwise if, then, otherwise ...) )

If < conditional expressions >
? Then
? Instructions
elif < conditional expressions >
? Then
? Instructions
Else
? Instructions
Fi
Where elif can have multiple

Case syntax

Case "Variable" in
? value 1)
? Directive 1 ...
? ;;
? value 2)
? Directive 2 ...
? ;;
?*)
? Directive 3 ...
Esac

When the value of the variable is value 1 o'clock, execution of Directive 1, and so on, does not conform to the instruction of last *)

While statement

While < conditional expressions >
Do
? directive:
Done

Description
1 while on condition detection, if the execution command is set, done, and then detected, if established, and executed again until the condition is not met, stop the loop
2 while ture indicates that the condition is always true and will always loop (while [1] and while ture)

How the while loop reads files by row
Method One

exec < file
While Read line
Do
? Instructions
Done

Method Two

Cat File|while Read Line
Do
? Instructions
Done

Method Three

While Read line
Do
? Instructions
Done<file

Until syntax

Until < conditional expressions >
Do
? directive:
Done

Note: The condition will not be established, the execution of the cycle, the condition is set to stop

For syntax

1 for variable name in variable list
Do
? directive:
Done

2 for ((EXP1;EXP2;EXP3))
Do
? directive:
Done

Description
The for is followed by 3 expressions, the first is the variable initialization, the second is the range of the variable, the third is the variable self-addition or decrement, and when the first initialization value conforms to the second variable range, the loop, otherwise, exits.

**select statements

Select variable name [in menu Value list]
Do
? Instructions..
Done

Shell programming If syntax, case syntax, while statement, until statement, for statement, select statement

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.