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
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
How to create a string hash
How to replace a file with content from another file?
Copies the original file and overwrites the target file (hence-f
which stands for "force").
In case you are attempting to copy just the content of the file try:
This will overwrite all the content of the second file with the content from the first. However, your owner, group, and permissions of the second file will be unchanged.