User Tools

Site Tools


bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
bash [2023/01/17 11:19] – created rogerbash [2023/01/17 11:24] roger
Line 3: Line 3:
 Useful Bash code, with no particular order Useful Bash code, with no particular order
  
 +===== Add safeguards on every script =====
 +
 +At the top of the file, always start your scripts with:
 +
 +<code bash>
 +set -euo pipefail
 +</code>
 +  * ''-e'': The -e option will cause a bash script to exit immediately when a command fails.
 +  * ''-o pipefail'': This particular option sets the exit code of a pipeline to that of the rightmost command to exit with a non-zero status, or to zero if all commands of the pipeline exit successfully.
 +  * ''-u'': This option causes the bash shell to treat unset variables as an error and exit immediately. 
bash.txt · Last modified: 2023/01/17 11:27 by roger