Linux shell Programming (ii) Condition testing

Source: Internet
Author: User

There are three types of conditions that are commonly tested in bash

Conditional test expression: [expression] [[expression]]

First: Integer test:

-eq tests whether two integers are equal, such as [$A-eq $B]
-ne test two integers in different sizes
-GT Test if one number is greater than the other (great than)
-LT Test if one number is less than the other (lesser than)
-ge greater than or equal to
-le less than or equal to
-ne Not equal to

The second type: file test:

-e file name or file path test file exists Eg:[-e/etc/inittab] if[!-e $FILE]
-F file name or file path test file is normal file
-d file name or file path test file is directory
-R-W-X tests whether the current user has read and write execution permissions on the specified file Eg:[-x/etc/rc.d/rc.sysinit]

The third type: string test:

= = is used to test for equality of strings. If you use =, you have a space at both ends.
! = tests whether to vary
>
<
-N String: Tests whether the specified string is empty, empty is true, and not empty is false.
-Z String: Tests whether the specified string is not empty, is true, empty is false

Linux shell Programming (ii) Condition testing

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.