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