Linux Test Statement (tests)

Source: Internet
Author: User

Linux Test Statements

Testing with the test command, returning 0 means that the test was successful and returning 1 indicates a failure.

1. File Status Test

File status test refers to the permissions of the file, there is no, attributes, types and other content to judge.

File Test parameter list

-d test file is a catalog file

-S test file is not empty

-F Test file is a regular file

-W test file is writable

-L Test if the file is a symbolic connection

-U Test whether the file has suid bit settings

-X Test whether the file can be executed

-R Test file is readable

2. Numerical test

The numerical test is to compare the size relationship of two values

1) test grammar with the test command: Test first operand numeric comparer second operand

2) use [] instead of the test command syntax:[ first operand numeric comparer second operand ]

Note:[ must have a space ] before must also have a space

Numeric comparison characters

-eq equals

-ne Not equal to

-ge greater than or equal to

-GT greater than

-le less than or equal to

-lt less than

3. String test

A string test is to compare two strings for equality, or to determine whether a string is empty

The method is similar to a numeric test by comparing the following characters:

= tests whether two strings are equal

! = Tests whether two strings are not equal

-Z Test string is empty

-N test string is non-null

4. Logic Test

-A: logical and, when both sides of the operator are true, the result is true, otherwise the result is false.

-O: logical OR, at least one of the operators is true, the result is true, otherwise false.

! : Logical No, only if the condition is false - Returns the result as true

Linux Test Statement (tests)

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.