Traditional if statements -- use conditional expressions as if conditions
If [conditional expression]
Then
Command
Command
Command
Else
Command
Command
Fi
Conditional expressions
File expression
If [-F file] If the file exists
If [-d...] If the directory exists
If [-s file] If the file exists and is not empty
If [-r file] If the file exists and is readable
If [-W file] If the file exists and can be written
If [-X file] If the file exists and can be executed
Integer variable expression
If [int1-EQ int2] If int1 is equal to int2
If [int1-ne int2] is not equal
If [int1-ge int2] If> =
If [int1-GT int2] If>
If [int1-Le int2] If <=
If [int1-lt int2] If <
String variable expression
If [$ A = $ B] If string1 is equal to string2
A string can be equal by a value.
If [$ string1! = $ String2] If string1 is not equal to string2
If [-N $ string] If the string is not empty (not 0), 0 (true) is returned)
If [-Z $ string] is null
If [$ Sting] If the string is not null, 0 is returned (similar to-N)
Non-logical! Inverse of conditional expressions
If [! Expression]
If [! -D $ num] If the directory does not exist $ num
Parallel Logic with-a conditional expression
If [expression 1-A expression 2]
Or of a logical or-O condition expression
If [expression 1-O expression 2]
Logical expression
Expression and the previous =! =-D-F-X-ne-eq-lt
Logical symbols are normally connected to other expressions without any parentheses ().
If [-z "$ jhhome"-a-d $ home/$ num]
Note that logic and-A and logic or-O are easily mixed with the operator numbers of other strings or files.
The most common assignment method is to evaluate the variables = both sides before the assignment.
Whether the test variable on the left is empty, and whether the test directory (value) On the right exists (value is valid)
If test $ num-EQ 0 is equivalent to if [$ num-EQ 0]