Shell programming in Linux-conditional Testing

Source: Internet
Author: User

 

1.Test File status

Table 1 File status test

-D directory-s file length is greater than 0, not empty

-F: regular file

-L symbolic connection

-R readable-x executable

-S file length is greater than 0, not empty

-W writable

-The U file has the s u I d bit setting.

-X executable

 

2.Use logical operators during testing

-Logic A and the operators are true on both sides, and the result is true. Otherwise, the result is false.

-O logic or, if either side of the operator is true, the result is true. Otherwise, the result is false.

Example:

[-R t.txt-a-W t.txt]

Echo $?

0

 

3.String Testing

= Two strings are equal.

! = Two strings.

-Z empty string.

-N is a non-empty string.

Example:

Test-Z $ path

Echo $?

1

 

4.Test Value

-The EQ value is equal.

-The ne values are not equal.

-The first number of GT is greater than the second number.

-Lt: the first number is smaller than the second number.

-The first number of Le is less than or equal to the second number.

-The first number of Ge is greater than or equal to the second number.

Example:

[80-lt 100]

Echo $?

0

 

5. exprUsage:

Expr 10/* 10

100

Extpr 10/10

1

 

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.