Shell comparison operator

Source: Internet
Author: User
Operator Description Example
File comparison operator
-EFilename IfFilenameYes, true [-E/var/log/syslog]
-DFilename IfFilenameIs a directory, it is true [-D/tmp/mydir]
-FFilename IfFilenameIs a regular file, it is true [-F/usr/bin/grep]
-LFilename IfFilenameIs a symbolic link, it is true [-L/usr/bin/grep]
-RFilename IfFilenameReadable, true [-R/var/log/syslog]
-WFilename IfFilenameWritable, true [-W/var/mytmp.txt]
-XFilename IfFilenameExecutable, true [-L/usr/bin/grep]
Filename1-NtFilename2 IfFilename1RatioFilename2New, true [/Tmp/install/etc/services-nt/etc/services]
Filename1-OtFilename2 IfFilename1RatioFilename2Old, true [/Boot/bzImage-ot arch/i386/boot/bzImage]
String comparison operator[Size =-1] (please note the use of quotation marks, this is a good way to prevent space from disturbing the code)
-ZString IfStringIf the length is zero, it is true. [-Z "$ myvar"]
-NString IfStringNon-zero length, true [-N "$ myvar"]
String1=String2 IfString1AndString2Same, true ["$ Myvar" = "one two three"]
String1! =String2 IfString1AndString2Otherwise, true ["$ Myvar "! = "One two three"]
Arithmetic comparison operator
Num1-EqNum2 Equal [3-eq $ mynum]
Num1-NeNum2 Not equal [3-ne $ mynum]
Num1-LtNum2 Less [3-lt $ mynum]
Num1-LeNum2 Less than or equal [3-le $ mynum]
Num1-GtNum2 Greater [3-gt $ mynum]
Num1-GeNum2 Greater than or equal [3-ge $ mynum]

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.