Linux Conditional Test Statement

Source: Internet
Author: User

Linux control statements need to use a variety of conditions, and the conditions are divided into different types.

To test an expression:

(1) Integer test

A-GT B: Greater Than

A-ge B: Greater than or equal to

A-eq B: Equals

A-le B: Less than or equal to

A-ne B: Not equal to

A-lt B: Less than

Example: 650) this.width=650; "src=" Http://images0.cnblogs.com/blog2015/764880/201506/021729231336104.x-png "/>

(2) String test

A > B

A<b

A<=b

A>=b

A! =b: Not equal to

A==b or A =b: equals

-Z A: Determine whether a is empty, empty is true, not empty for false

-N A: Determine whether a is empty, not empty is true, empty is false

(3) file test

-e $file: exists, exists as true
-A $file: ditto, deprecated
-F $file: Whether the file exists and is a normal file;
-D $file: Exists and is a directory
-H $file: exists and is a symbolic link file
-L $file: Ibid.
-B $file: exists and is a block device file
-C $file: exists and is a character device file
-S $file: Socket file
-P $file: Pipe file


-R $file: Whether the current user has read access to this file
-W $file: Write permission
-X $file: Execute Permissions
-U $file: Whether the file has suid permissions
-G $file: Whether the file has Sgid permissions
-K $file: Whether the file has sticky permissions


-O $file: Whether the current user is the owner of the file
-G $file: Whether the current user belongs to a group belonging to a file

-N $file: Whether the file has been modified since it was last read
[-n/tmp/fstab]
echo $?

$f 1-nt $f 2: Is file F1 newer than file F2
$f 1-ot $f 2: File F1 is older than file F2
$f 1-ef $f 2: Two files is a hard link to the same file

Combination test conditions
Add a logical operator to a condition Note: commands cannot be used with these
Or,-O:
With:-a:[$uid-gt 0-a $uid-lt 500]
Non -:!
-Z: Empty
Command connection: Short-circuit operator, string command to use this type of command
and &&
Or: | |
Non: [! EXPRESSION]

650) this.width=650; "src=" Http://images0.cnblogs.com/blog2015/764880/201506/021801141489597.png "/>


Linux Conditional Test Statement

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.