Shell Script application (if statement's structure)

Source: Internet
Author: User
1, test: the detection of the expression is established, the return value is 0, otherwise, not 0
Method:
1) test expression
2) "Expression"
2. File test:
-D: Whether it is a directory
-F: Whether it is a file
-E: whether there is
-r: Whether Read permission is available
-W: Write permission
-X: Whether there are execute permissions
3, Integer value comparison:
-eq: Equals
-ne: Not equal to
-GT: Greater Than
-LT: Less than
-ge: greater than or equal to
-le: Less than or equal to
4. String comparison:
=: string content is the same
! =: string content is not the same
-Z: string content is empty
5. Logic Test:
-A or &&: Also, two conditions are true at the same time, the preceding command executes successfully before executing the subsequent command
-O or | | : Or, a condition is true
! : No, true if condition is not satisfied
6, if statement: Conditional Judgment Statement, the establishment is executed, otherwise launched or the next judgment, up to execute a command
1) Single branch: Judge once, set up execution, do not set out
If "Conditional expression"
Then
Command
Fi
2) Double branch: Judge once, set up execute an order, do not set to execute another command
If "Conditional expression"
Then
Command 1
Else
Command 2
Fi
3) Multi-branch: Judge multiple times, execute sequentially
If "Conditional expression"
Then
Command 1
Elif "Conditional expression"
Then
Command 2
Else "conditional expression"
Then
Command 3
Fi

Shell Script application (if statement's structure)

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.