Common comparison operators in shell programming

Source: Internet
Author: User

Conditional judgment statements are not necessary in any program writing, as is the case in shell programming, where the comparison operators that are often used in the shell's test commands are sorted into numeric comparisons, string comparisons, and file comparisons.

Numerical comparison:
N1-eq N2 Check if N1 is waiting for N2
N1-ge N2 Check if N1 is greater than or equal to N2
N1-GT N2 Check if N1 is greater than N2
N1-le N2 Check if N1 is less than or equal to N2
N1-lt N2 Check if N1 is less than N2
N1-ne N2 Check if N1 is not equal to N2

string comparison:
STR1 = str2 Check if STR1 is the same as str2
Str1! = str2 Check if STR1 is different from str2
STR1 < STR2 Check if STR1 is smaller than str2
str1 > STR2 Check if STR1 is bigger than str2.
-N str1 Check that the length of the str1 is not 0
-Z str1 Check if the length of the str1 is 0

File comparison:
-D File Check if file exists and is a directory
-E File Check if file exists
-F File Checks if file exists and is a file
-R File Check if file exists and is readable
-S file Checks if file exists and is not empty
-W File Checks if file exists and is writable
-X File Check if file exists and can be executed
-O File Checks if file exists and is owned by the current user
-G file Checks if file exists and the default group is the same as the current user
File1-nt File2 Check if File1 is newer than file2
File1-ot File2 Check if File1 is older than file2

Common comparison operators in shell programming

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.