I can recommend starting every bash script with
set -euxo pipefail
The "u" has basically the same effect as the question mark, but for every variable usage.