With this script: tstNounset.sh
#!/bin/bash
set -x
set -o nounset;set -u
echo `echo $str`
function FUNC1() { echo $str; };export -f FUNC1;bash -c FUNC1
function FUNC2() { set -u;echo $str; };export -f FUNC2;bash -c FUNC2
echo "A - should not reach here?"
echo $str
echo "B - doesn't reach here."
I would like to prevent reaching "A", in a global manner, not requiring to check each variable for it.
Also without using set -e (as I take care of errors and workaround most already, as many also are only warnings).
I thought if there could have some way to detect "unbound variable" happened even from subshell/child, so I could force an exit from that?
I couldn't make things work from How to have a bash script perform a specific action on errors of _each_ command? or How to trigger error using Trap command also. I found this old question too.