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