Another post with stuff I can’t remember or might forget again 🤷♂️
» Bash shebang
Specify the explicit path:
|
|
Let the environment decide:
|
|
Explanation: Alec Bennett
» Fail fast … and more
Best added directly after the shebang.
|
|
or in short:
|
|
Reference: GNU Bash Manual - the set builtin
» Exit code of last execution
Check with $?
if the last executed program failed (0 = ok, everything else = failed)
|
|
Examples:
|
|
|
|
» Constants
Use readonly
. For example, a fixed array of OS names:
|
|
Reference: Jeff Lindsay et al. - bashstyle
» Strings equal check
|
|
Reference: tecadmin.net - Check if two strings are equal
» For Loops
|
|
Reference: Vivek Gite
» Loop until failure
|
|
Reference: nneonneo & Gurpreet Atwal
» Redirect Output
» Redirect Stdout
|
|
» Redirect Stderr
|
|
Reference: How to Redirect Stderr in Bash
» Redirect Stdout and Stderr
|
|
Reference: BASH Shell Redirect Output and Errors