Linux executes multiple commands consecutively and linux Multiple commands
If each command is separated by ";", the next command will be executed no matter whether the command at the front is successfully executed or not.
Here, the echo in the second command is intentionally written to one o, and the command execution error does not affect subsequent command execution.
In this case, if commands are separated by semicolons, they are separated into different lines. The execution of the next line of commands is not affected no matter whether the previous line is successful or failed.
$ Echo 1;Echoo 2; Echo 3; echo 4
1
-Bash: echoo: command not found
3
4
If commands are separated by "&", only the commands on the front are successfully executed, and the commands on the back are executed again.
Here, the echo in the second command is intentionally written to an o, and the command execution fails, so echo 3 is not executed, so echo4 is not executed.
$ Echo 1 &&Echoo 2& Echo 3 & echo 4
1
-Bash: echoo: command not found
If commands are separated by "|", only the command at the front end fails to be executed, and then the command at the back end is executed again.
Echo 1 is successfully executed, but echo 2 is not followed by echo 3, echo 4
Echo 1 | echo 2 | echo 3 | echo 4
1
Here, the execution of echoo 1 fails, so echo 2 is executed successfully, so echo 3 and echo4 are not executed.
Echoo 1| Echo 2 | echo 3 | echo 4
-Bash: echoo: command not found
2
Analyze several special examples based on the above rules, that is, examples of mixing centralized Separators
Echo 1 is successfully executed, followed by two "|" So echo 2 and echo 3 are not executed &&, the previous command combinations are considered successful, so echo 4 can be executed.
$ Echo 1 | echo 2 | echo 3 & echo 4
1
4
Echo 1 is successfully executed, and then echoo 2 is executed. Therefore, echo 3 is not executed, and "| ", therefore, echo 4 can be executed because the previous command combinations are considered failed.
$ Echo 1 &&
Echoo 2& Echo 3 | echo 4
1
-Bash: echoo: command not found
4
Echo 1 is successfully executed, and then echoo 2 is executed. Therefore, echo 3 is not executed, and ";" is encountered later, which is equivalent to putting the following command into a new line, in this way, all subsequent commands are executed, so echo 4 can be executed.
$ Echo 1 &&
Echoo 2& Echo 3; echo 4
1
-Bash: echoo: command not found
4
The execution of echoo 1 fails, followed by "|" So echo 2 is executed, echo 2 is executed successfully, followed by two "|" So echo 3 and echo 4 are not executed, the following encountered &, and the previous command combination was considered to be successful, so echoo5 was executed and an error occurred. Therefore, echo 6 was not executed, "; ", so echo 7 will be executed no matter how
$
Echoo 1| Echo 2 | echo 3 | echo 4 &&
Echoo 5& Echo 6; echo 7
-Bash: echoo: command not found
2
-Bash: echoo: command not found
7
Execute multiple commands at a time on a linux terminal
Add the & symbol in the middle of the command, for example, make & make install, to indicate that the previous command is executed after
In addition, The rpm-qa | wc-l pipe symbol indicates that the preceding command execution result is used as the input of the subsequent command.
Java executes multiple linux commands
The concept of DOS batch processing is used.
Similar functions are available in Linux.