From aeb6be7071582965c5909c24e124c0eb0eef193d Mon Sep 17 00:00:00 2001 From: Kevin Ernst Date: Sun, 18 Oct 2020 09:46:10 -0400 Subject: [PATCH] Mention set -u and ${arg:?message} Closes #29. Closes #37. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bddbb5d..88db17b 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,11 @@ Keep in mind this is not for general shell scripting, these are rules specifical * Always use `local` when setting variables, unless there is reason to use `declare` * Exception being rare cases when you are intentionally setting a variable in an outer scope. * Variable names should be lowercase unless exported to environment. - * Always use `set -eo pipefail`. Fail fast and be aware of exit codes. - * Use `|| true` on programs that you intentionally let exit non-zero. + * Fail fast and be aware of exit codes + * Always use `set -uo pipefail` (fail on unset variables, and fail if any command in a pipeline fails) + * Consider also using `set -e` (terminate script on _any_ non-zero exit), with an ERR trap + * Use `|| true` on programs that you intentionally let exit non-zero. + * Use something like `: ${arg:?Expected argument 'arg'}` when you don't have time to do proper argument parsing * Never use deprecated style. Most notably: * Define functions as `myfunc() { ... }`, not `function myfunc { ... }` * Always use `[[` instead of `[` or `test`