by the_common_man · 10y ago · 0 comments
* readonly - describing these in library scripts is a bit dangerous since the readonly is not specific to the file. So, unless you have some namespacing pattern for globals, this will bite you
* I didn't see any recommendation but always start with set -eux -o pipefail. set -e has it's own set of pitfalls but it's best to learn what the pitfalls are and work with it :-) It helps in the long run.
* When using set -u, use the FOO={FOO:-} syntax to initialize defaults for all your env vars.
On point 3: `: ${FOO:-some default value}` is the typical pattern for ensuring a default value is set.
See http://mywiki.wooledge.org/BashFAQ/105 for some (most) of the pitfalls.
Or consider the last example from the wiki link above:
set -e
f() { local var=$(somecommand that fails); }
f # will not exit