You can use the semicolon ";", the double ampersand "&&" and the Double vertical bar "| |" in Linux To connect multiple commands.
1.3.1 Semicolon;
When multiple commands want to be executed at the same time on a single line, a semicolon ";" can be used after each command. There is no logical relationship between multiple commands, and all commands written are executed, even if a command has errors and does not affect other commands.
ls das; Echo " Hdakl "
Ls:cannot access das:no such file or directory
Hdakl
1.3.2 &&
Logic and. Command1 && Command2, Command2 is executed only if Command1 is executed correctly, Command1 is not performed if Command2 is not executed correctly. How to judge correctly, bash internal will pass the predefined variable "$?" To judge.
Echo " Hdakl " ls
Hdakl
Ls:cannot access ds:no such file or directory
ls Echo " Hdakl "
Ls:cannot access das:no such file or directory
1.3.3 | |
Logical OR. Command1 | | Command2, Command2 will not be executed unless Command1 is executed correctly command2,command1 execution is performed correctly. | And && are short-circuiting symbols, which have a logical relationship between the commands around the symbol.
ls Echo " Hdakl "
Ls:cannot access das:no such file or directory
Hdakl
Echo " Hdakl " ls ds
Hdakl
general use of && and | | , it's basically logical and logical, or :command1 && Command2 | | Command3. Because in practice, Command2 and Command3 should all be commands that you want to execute. If Command1 is executed correctly, $? equals 0, executes Command2, and then the situation executes Command3, if the Command1 error executes, $? is not equal to 0, does not execute Command2, but then according to this non-0, judged the | | The right side should be executed.
Shell Script Raiders (learning notes)--1.3 command logical execution order