Перейти к содержанию

Bash Reference

Bash Reference Manual

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

How to put a line comment for a multi-line command

  pip-compile --upgrade \
    requirements/in/unit_test.in `# Dependencies specific to unit tests.` \
    requirements/in/requirements.in `# All base project dependencies are required for the tests to work.` \
    --output-file=- > requirements/out/unit_test.txt

What's next?

  1. Found this article helpful? Share it and help spread the knowledge!
  2. Found a mistake or have ideas 💡 on what and how I can improve? Message me on Telegram.
  3. Want to know more about me? Read here.