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

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 

How to create a string hash

echo -n 'Some text' | base64
# Output: U29tZSB0ZXh0

How to replace a file with content from another file?

cp -f [source_file] [destination_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:

cat /first/file/same_name > /second/file/same_name
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.