From 3276c74d49bfd26a58c05e2984ebddbdb58f6ffe Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Sat, 14 May 2022 16:08:29 -0500 Subject: [PATCH] add more info about BASH options --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 4ab8425..467adfe 100644 --- a/README.md +++ b/README.md @@ -3255,9 +3255,25 @@ dd if=/dev/zero of=//dev/shm/200m bs=1M count=200 watch -n 1 wc -l filename ``` +##### Un/Safely pipeline +```bash +# These options can make your code safer but, depending on how your pipeline is written, it might be too aggressive +# or it might not catch the errors that you are interested in + +# for reference see https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +# and https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail + +set -o errexit # exit immediately if a pipeline returns a non-zero status +set -o errtrace # trap ERR from shell functions, command substitutions, and commands from subshell +set -o nounset # treat unset variables as an error +set -o pipefail # pipe will exit with last non-zero status, if applicable +set -Eue -o pipefail # shorthand for above (pipefail has no short option) +``` + ##### Print commands and their arguments when execute (e.g. echo `expr 10 + 20 `) ```bash set -x; echo `expr 10 + 20 ` +set -o xtrace; echo `expr 10 + 20 ` # this might be easier to remember ``` ##### Print some meaningful sentences to you (install fortune first)