&& means to run it if the previous command was successful. In Unix that generally means exit status 0.
$ ls barfoofba && echo "This will not be echo'd"
ls: cannot access 'barfoofba': No such file or directory
$ ls bar && echo "This will be echo'd"
This will be echo'd
In the first instance, ls did not succeed, so it exited with a non-zero exit status, and bash did not run the second command.
In the second example, I ls'd a existing file, so ls exited with 0 as exit status, and the command was executed.
If you want to run commands unconditionally, e.g. not dependent on the result of the first, you may separate them with ; like this
command1; command2; command3
and so forth.
Thus you may do
ls -lR ; sleep 4 ; gnome-terminal
In addition to && and ; you have || which is the opposite of &&: Only run the command if the previous command failed with a non-zero exit status. If the first command succeeds, the next will not be executed. If it fails, the next will be executed.
So in short:
&&: Run if preceding command exited with 0
;: Run unconditionally
||: Run if preceding command exited with a non-zero exit status.
&: Run both commands in paralell, the first in background and second in foreground.
&&conditon and not run the following command. And vice versa for the||operator. – Cave Johnson Jan 28 '19 at 23:00ls -l && sleep 4 && gnome-terminalworking butls -lR && sleep 4 && gnome-terminalnot working ? You can try on your machine.. – Abhishek Kamal Jan 29 '19 at 01:40error.h). Happy return codes are all alike... – chrylis -cautiouslyoptimistic- Jan 29 '19 at 02:48ls -lR /always fail... – vidarlo Jan 29 '19 at 05:53lsbe, for instance? – IMSoP Jan 29 '19 at 15:29if (!function())everywhere in C. – chrylis -cautiouslyoptimistic- Jan 29 '19 at 17:38