1. Condition testing: Test or [
If the test result is true, the exit status of the command is 0, and if the test result is false, the exit status of the command is 0
Operation Result:
Test commands with and, or, not
[ ! Expr]: Expr can be any of the test conditions in the table above. Represents a logical inverse
[Expr1-a EXPR2]: EXPR1 and EXPR2 can be any of the test conditions in the table above,-a represents the logic and
[Expr1-o EXPR2]: EXPR1 and EXPR2 can be any of the test conditions in the table above,-o represents a logical OR
2. If/then/elif/else/fi
The shell uses a few commands such as if, then, elif, else, fi to implement branch control
Operation Result:
The shell also offers && | | Syntax,&& equivalent to "If...then ...", while | | Equivalent to "if Not...then ...".
-A and-O are only used to connect two test conditions in a test expression
3, Case/esac
Shell script case can match strings and wildcard, each matching branch can have several commands, at the end must be;; End, executes the row to find the first matching branch and executes the line corresponding command, and then jumps directly to Esac
Operation Result:
Looping statements
4, For/do/done
Here's an example:
Operation Result:
5, While/do/done
Here's an example:
Operation Result:
6. Positional parameters and special variables
There are many special variables that are automatically assigned by the shell, and the following are common positional and special variables
$ argv[0 equivalent to the C language main function]
$ ... C language words main function of argv[1], argv[2] ...
These are called positional parameters (positional Parameter)
$# equivalent to the argc-1 of the C language main function
[Email protected] Indicates the parameter list "$" "$" ..., for example, can be used in the for loop in the back.
$? Exit Status of the previous command
Conditional testing and looping statements in the shell