- If I run CLI command
A
, I want to run commandB
immediately whenA
finishes. B
should not start running beforeA
finishes.- Time is money, so the terminal should not sit idle.
B
should run ASAP afterA
finishes.
Much like in JavaScript, &&
in bash
is the 'logical AND' operator. It only executes the right side after the left side evaluates as true
.
$ true && echo "This will be output"
This will be output
$ false && echo "This will not be output"
$
This sequence of commands is so common that many devs make an alias for it. The alias includes the &&
operator.
npm install
runs. This can take a while if you have lots of dependencies or are installing a large package with lots of dependencies.- After
npm install
(finally) finishes,npm start
runs.
npm install && npm start
- This excellent concise StackOverflow answer.
- This awesome very detailed StackOverflow answer.