This is part thirteen of a series on how to approach bash programming in
a way that’s safer and more structured than your basic script.
See part 1 if you want to catch the series from the start.
Last time, we discussed techniques for working in strict mode. This
time, let’s TDD a function to implement strict mode.
As a reminder, setting any of the strict mode settings involves calling
set -o. In order to unset any of them, you use set +o instead.
This time, let’s start with the tests. We’ll implement our
strict_mode function in lib/support.bash.
This fails since we don’t yet have strict_mode. Let’s remedy that.
This passes, so on to the next test:
Run shpec and failure again. Good.
Pass. The tests for pipefail and nounset are similar. I don’t
bother testing the off setting for the other two.
Here’s the entirety of strict_mode testing in
And finally, lib/support.bash:
Continue with part 14 - updated outline