strictbash offers a convenient way of enabling the (unofficial) Bash Strict
Mode.
Also, with one flag, strictbash allows you to pass your script through
shellcheck before it's run.
strictbash is an experiment and probably shouldn't be used in production :).
Default strictbash usage
Using strictbash is straightforward: simply use the following shebang:
#!/usr/bin/env strictbashThis is equivalent to:
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'To additionally run shellcheck before your script is invoked:
#!/usr/bin/env -S strictbash --shellcheckTo disable setting the IFS to \n\t, pass --no-ifs:
#!/usr/bin/env -S strictbash --no-ifsStrictbash being used with the shellcheck option
strictbash is a single bash script with no dependencies (unless you want to
use its shellcheck feature, in which case you must install
shellcheck). Install
by:
curl -O https://raw.githubusercontent.com/jamespwilliams/strictbash/main/strictbash
# move somewhere on your $PATHIf you have Nix (and flakes enabled), you can try it out with:
nix shell github:jamespwilliams/strictbash
or install with
nix profile install github:jamespwilliams/strictbash
Here's a file you can paste somewhere as a test:
#!/usr/bin/env -S strictbash --shellcheck
echo $undefined
