Conditional judgment statements: files, numeric values, strings
You can test whether a condition is true with test or []. If the test result is true, the exit status of the command is 0, if false, the status is 1.
File testing
Format: test option file or [option file]
-b file block file
-c file character file
-d file directory
-e file exists
-p file pipeline
-r file readable
-s file greater than 0
-w file writable
-x file executable
F1-ef f2 F1 and f2 are linked to the same file (Korsh shell)
F1-nt f2 F1 is newer than f2
F1-ot f2 F1 is older than f2
The-a logic and the operator are true on both sides, and the result is true, otherwise it is false.
-o logical OR, either side of the operator is true, the result is true, otherwise it is false.
! Logic no, the condition is false, the result is true
Integer comparison test
Format: test int1 operator int2
-eq values are equal.
-ne values are not equal.
-the first number of gt is greater than the second number.
-the first number of lt is less than the second number.
-le the first number is less than or equal to the second number.
-ge the first number is greater than or equal to the second number.
N1-eq N2 N1 and N2 are equal
N1-ge N2 N1 is greater than or equal to N2
N1-gt N2 N1 is greater than N2
N1-le N2 N1 is less than or equal to N2
N1-lt N2 N1 is less than N2
N1-ne N2 N1 is not equal to N2
String test
Format: test option string or [option string]
= two strings are equal.
! = two strings are different.
-z empty string.
-n non-empty string.
S1 = S2 equal
S1! = S2 S1 is different from S2
S1
< s2 s1的ASCII在s2前 s2 >ASCII of S2 S1 after S2