bash is “sh-compatible” some features of
bash will break or cause unexpected behaviour in
Don't give scripts an
bashscript, not an
If you're piping to
grep multiple times only the last
grep in the sequence can be called with
First line of the script that indicates which interpreter is used to execute the file. The
#! must be at the very start of the file, with no spaces or blank lines before it.
bashis not always in
/bin, particularly on non-Linux systems.”
bash and tell it to read the script
myscript. When executing the script this way the shebang line (
#!) is just a comment,
bash does nothing with it
We can give the script executable permission. Instead of calling
bash manually, we can execute
chmod +x myscript # Mark myscript as executable ./myscript # Directly execute myscript
myscript is executed this way, the shebang line (
#!) is used to determine which interpreter to use.
Print every command before its execution, replacing the variables with their real values.
set -euo pipefail # -e: Exit if any command returns non-zero status code # -u: Prevent using undefined variables # -o pipefail: Force pipelines to fail on first non-zero status code