1. Introduction of the Linux command return value
When the shell executes a command, it has a return value that is stored in the shell variable $?. When $? is 0 o'clock, the command execution succeeds; when $ = 1 o'clock, the command execution fails.
2. &&
The syntax format is as follows:
Command1 && command2 && ...
- Use && connection between command to implement logic and function
- The command on the right side of,&& will be executed when the commands on the left side of && execute successfully (command return value $?=0).
- As long as a command execution is unsuccessful (command return value $?=1), subsequent command will not be executed
3. | |
The syntax format is as follows:
Command1 | | Command2 | | .....
- Use between command | | Link to implement logic or functionality
- When | | The left command execution is unsuccessful (command return value $?=1), | | The command on the right will be executed.
- As long as there is a command execution Success (command return value $?=0), subsequent command will not be executed.
4 ()
The syntax format is as follows:
(Command1;command2; ...)
- A command needs to have a single physical row, and if multiple comand need to be placed on the same line, the command delimiter (;) delimited) is required between the commands. The effect of execution is equivalent to multiple separate commands executed separately.
- () indicates that multiple command executions are performed as a whole in the current shell. Note: Thecommand combination is executed under the current working directory, although the command has the command to switch directories.
- command combination often commands execution control (&& or | |) Used in combination.
&& in Linux shell | | and ()