Three types of shell script condition judgment (Memo)

Source: Internet
Author: User

String comparison: Result

String1 = string2 string1 equals string2: True, otherwise false

String1! = String2 string1 equals to string2: false, otherwise true

-When n string is not equal to NULL: True, otherwise false

-Z string when string is null: true; otherwise, false

 

Arithmetic comparison result

Expression1-EQ expression2 expressions are equal: True, otherwise false

Expression1-ne expression2 expressions are not equal: True, otherwise false

When expression1-GT expression2 expression expression1 is greater than expression2: True, otherwise false

When the expression1-ge expression2 expression expression1 is greater than or equal to expression2: True, otherwise false

When expression1-lt expression2 expression expression1 is less than expression2: True, otherwise false

When the expression1-Le expression2 expression expression1 is less than or equal to expression2: True, otherwise false

! If expression is true, it is false.

 

File condition Result

-D When file is a directory: true; otherwise, false

-E file: true if file exists; otherwise, false. Note: historical reasons-e option is not portable. Therefore, use-F instead.

-F file exists: true; otherwise, false

-G file: true if the file is set by "Set-group-ID"; otherwise, false

-R file is readable: true; otherwise, false

-S file size is greater than 0: True, otherwise false

-U file is set to true by "Set-user-ID"; otherwise, false

-W file writable: true; otherwise, false

-X file is an executable file: true; otherwise, false

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.