Conditional test in Shell

Source: Internet
Author: User

Condition test Type in Bash script: integer test

String test

File test

Expressions for conditional tests: [Expression]

[[expression]] expression must have a space before and after it

integer test :-eq: Tests whether two integers are equal and equal to True

-ne: Test whether two integers are unequal, not equal to True

-ge: Tests whether a number is greater than or equal to another number

-le: ..... ..... Less than or equal to ....

-gt: ..... ..... Greater than..........

-lt: ......... Less than..........

The logical relationship between commands (between statements) in bash:

Logic with: && The result of the previous command execution is false, the second statement is no longer executed

Logical OR: | |, the previous command executes the result is true, the second statement is no longer executed

Logical non-:!

    1. You can use logical symbols after a condition test to determine whether the second instruction executes

    2. Determine the logical relationship between commands by using the control structure of the conditional judgment

      eg:[expression] && statement1 | | Statement2

      Indicates that if the test expression is true, statement 1 is executed, or statement 2 is executed




If control structure:

if judgment condition; then

Statement

Fi

if judgment condition; then

Statement1

Else

Statement2

Fi

Note: The return value type of the judging condition must be Boolean type


file test: -e/path/to/filename test file is present

-F test Specifies that the file is not a normal file

-D test Specifies whether the file is a directory file

-R tests whether the file has Read permissions

-W Tests if the file has write permissions

-X tests whether the file has Execute permissions


String Test: =

==

Equal and double equals, [string1 = string2] Tests whether two strings are equal

-N String tests whether the specified string is empty and Null is true

-S string tests whether the specified string is not empty and is not empty for true

This article is from the "Zxcvbnm Xuan ye" blog, please be sure to keep this source http://10764546.blog.51cto.com/10754546/1707597

Conditional test in Shell

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.