I want to check what options are enabled for my current shell. For example, I want to know whether I was invoked with -x or -e or any number of other options.
I source a shell script with shebang line #!/bin/bash -x and later attempt to turn off 'x' with a set +x at the end of the script. Now I want to check whether my set +x line succeeded.
Attempted solution
I've discovered printenv and set as ways to inspect some info about the current shell, but neither of them seem to contain a variable that stores x e or the like.
1 Answer
It's in the $- variable.
See the documentation for the set command -- scroll down to the end and you'll see "The current set of options may be found in $-."
A quick demo
$ bash
$ echo $-
himBH
$ set -f; set +H
$ echo $-
fhimB
$ [[ $- == *i* ]] && echo This is an interactive shell
This is an interactive shell