File comparison operator, comparison operator

Source: Internet
Author: User

File comparison operator, comparison operator

File comparison operator
-E filename if filename exists, it is true [-e/var/log/syslog]
-D filename if filename is a directory, it is true [-d/tmp/mydir]
-F filename if filename is a regular file, it is true [-f/usr/bin/grep]
-L filename if filename is a symbolic link, it is true [-L/usr/bin/grep]
-R filename if filename is readable, it is true [-r/var/log/syslog]
-W filename if filename is writable, it is true [-w/var/mytmp.txt]
-X filename if filename is executable, it is true [-L/usr/bin/grep]
Filename1-nt filename2 if filename1 is newer than filename2, true [/tmp/install/etc/services-nt/etc/services]
Filename1-ot filename2 if filename1 is older than filename2, true [/boot/bzImage-ot arch/i386/boot/bzImage]
String comparison operator (please note the use of quotation marks, which is a good way to prevent space from disturbing the code)
-Z string if the string length is zero, it is true [-z "$ myvar"]
-N string if the string length is not zero, it is true [-n "$ myvar"]
String1 = string2 if string1 is the same as string2, it is true ["$ myvar" = "one two three"]
String1! = String2 if string1 is different from string2, it is true ["$ myvar "! = "One two three"]
Arithmetic comparison operator
Num1-eq num2 equals to [3-eq $ mynum]
Num1-ne num2 is not equal to [3-ne $ mynum]
Num1-lt num2 less than [3-lt $ mynum]
The num1-le num2 is less than or equal to [3-le $ mynum]
Num1-gt num2 greater than [3-gt $ mynum]
Num1-ge num2 is greater than or equal to [3-ge $ mynum]

PS (reproduced): http://zhidao.baidu.com/link? Url = qxbyyzZeyrF-hPVn2OGrFRsUTXp1XERdFCLJAnC6UkDjpb_vTdnWhgC8CiQTzS8K1hbtOjJQEZ9XZobQl74Wxq

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.