POSIX sh check (test) value of builtin set option

In POSIX sh you may set options with set:


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';;