Simple shell scripts for tasks without variables are generally competent. However, when executing some decision-making tasks, it is necessary to include the IF/then condition judgment. Shell script programming supports such operations, including comparison operations and determining whether a file exists. The basic if condition command options include:
-Eq-compare whether two parameters are equal (for example, if [2-EQ 5])
-Ne-compare whether two parameters are not equal
-Lt-parameter 1: whether it is smaller than parameter 2
-Le-parameter 1: whether it is less than or equal to parameter 2
-GT-whether parameter 1 is greater than parameter 2
-Whether Ge-parameter 1 is greater than or equal to parameter 2
-F-check whether a file exists (for example, if [-F "FILENAME"])
-D-check whether the directory exists
Almost all judgments can be implemented using these comparison operators. In the script, the common-F Command Option checks whether a file exists before executing it.