&& and
|| Or
# when two files are present
[[email protected] ~]# ls 1.txt && ls 2.txt
1.txt
2.txt
# 10.txt file does not exist
[[email protected] ~]# ls 10.txt && ls 2.txt
LS: Unable to access 10.txt: No file or directory
[[email protected] ~]# ls 10.txt | | LS 2.txt
LS: Unable to access 10.txt: No file or directory
2.txt
# 20.txt file does not exist
[[email protected] ~]# ls 1.txt && ls 20.txt
1.txt
LS: Unable to access 20.txt: No file or directory
[[email protected] ~]# ls 1.txt | | LS 20.txt
1.txt
Conclusion:
&& the left and right side of the symbol is two commands, if the previous command can be executed successfully, it will execute the following command;
|| The left and right sides of the symbol are two commands, and if the previous command does not execute successfully, it will execute the subsequent command.
There is another one; the command that precedes it executes successfully, and all subsequent commands execute.
This article from the "Linux" blog, reproduced please contact the author!
Connectors in the shell (and, and, or)