I. Condition TEST ACTION
The shell environment determines whether the execution succeeds based on the return status value ($?) after the command executes, or if the return value is 0 o'clock, which indicates a success or failure or exception. You can test specific conditions by using a specialized test tool---the test command.
(1) file test
A file test refers to a file or directory according to the specified path name, or whether the file is readable, writable, executable, etc.
(2) Integer value comparison: The integer value comparison refers to the relationship between the first number and the second number according to the given two integer values, such as whether it is greater than, equal to, less than the second number.
(3) string comparison: string comparison is usually used to check the user input, the system environment, such as whether the conditions are met, in the shelluanjing to provide interactive operation, l environment, can also be used to determine whether the user's location parameters meet the requirements.
(4) Logic test for multiple conditions: logical testing refers to the determination of dependencies between two or more conditions
Ii. using the IF statement: in a shell script application, the If statement is the most commonly used process control method, which is used to perform different operations with the specific condition test results.
(1) Single Branch if statement: For a light-pink-live selection structure, the corresponding code will be executed only when the condition is set, otherwise no action is taken.
The ① Condition Test Action Statement statement can be either a conditional expression statement or a command statement executed by another amount, or a command sequence that refers to one or more executable command lines. Also includes nested use of if or other process control statements
(2) Dual-branch if statement: for the two-branch selection structure, the requirements for the "condition is set" "condition is not established" to perform different operations respectively.
(3) Multi-branch If statement: Because the IF statement can be based on the test results of the establishment, do not set up separate operations, so can be nested use, make multiple judgments.
Shell Script 2