Linux Shell 04 Digital/string/file Test

Source: Internet
Author: User

I. Digital testing

Format: N1-op n2

Test Operation op:

EQ/NE/LE/GE/LT/GT--equals/not equals/less than equals/greater than/less than/greater than

1. A numeric comparison can use a special (()) operator, which is closer to the C language, see digital testing.

Two. String test

S1 = S2 #s1与s2是否相同

S1! = S2 #s1与s2是否不相同

S1 < S2 #s1是否小于s2

S1 > S2 #s1是否大于s2

-N S1 #s1长度是否大于0

-Z S1 #s1长度是否为0

1. String comparison is greater than less than the symbol "<>" needs to be escaped

if [$s 1 \> $s 2]then     " $s 1 is  greater than $s 2"else    "$s 2 is  greater than $ S1"fi

2. The string size comparison uses ASCII value comparisons of characters, that is, uppercase letters less than lowercase letters. (the sort command is sorted exactly the opposite way)

3. Undefined variable string length is 0

Three. File testing

Format: f1-nt F2 F1 is newer than F2

F1-ot F2 F1 is older than F2

-op file

OP Operator:

E/D/F/R/W/X/S/L/O/G--Presence/directory/File/readable/writable/executable/present and not empty/symbolic link/Current user owned/current group owned

1. Compare the new old times of the file by the creation time, and require two files are present, otherwise the failure condition is returned

if [-G $HOME/test      ]then " You is in the same group as the file " Else  "The file is not a owned by your group" fi       

Linux Shell 04 Digital/string/file Test

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.