Bash Reference
What is the purpose of &&
in a shell command?
&&
lets you do something based on whether the previous command completed successfully. That's why you tend
to see it chained as do_something && do_something_else_that_depended_on_something
.
Furthermore, you also have ||
which is the logical OR, and also ;
which is just a separator which
doesn't care what happend to the command before.
$ false || echo "Oops, fail"
Oops, fail
$ true || echo "Will not be printed"
$
$ true && echo "Things went well"
Things went well
$ false && echo "Will not be printed"
$
$ false ; echo "This will always run"
This will always run
if else then
if command; then command; else command; fi