In POSIX sh you may set options with set:
#!/bin/sh
set -u;
echo "$notset";
that gives expected:
parameter not set or null
but how to check if option -e is set or not?
I want at some point of my script to turn it off but set it back to on only if it was previously on.
The shell options are held in $- as a string of single characters. You test for -e with
case $- in
(*e*) printf 'set -e is in effect\n';;
(*) printf 'set -e is not in effect\n';;
esac
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With