In tutorials and how-to's I often see commands combined. For instance,
sudo apt-get update && sudo apt-get install pyrenamer
There seem to be four possible connectors: &, &&, || and ;. Though the & connector is clear to me (it sends a process to the background and leaves the terminal available), it is not clear what the difference is between && and ;. And I did not know of || until Kaya's comment.
The following questions deal with the difference between the two connectors, but do so mostly in the comments:
So here are a number of related questions:
- What is the difference between
;and&&? - When should you use them respectively? It would be nice to see some use cases: if I want to run a command and then after it shutdown my computer, which connector should I choose?
- What are their advantages and dangers? Robie Basak mentions in a comment to this answer that a command like
cd /somewhere_else; rm -Rf *can have destructive consequences if the first element in the command chain fails, for instance. - If relevant, where do they come from?
||is the same as&&except that it only executes the second command if the first one exited with a non-zero (unsuccessful) status. – Kaya Aug 20 '13 at 22:11set -ewill stop the script on failure as if all the commands were connected with&&. – choroba Aug 21 '13 at 18:21