In the case of bash
, that depends on whether $SHELLOPTS
is in the environment or not.
bash-4.4$ export SHELLOPTS
bash-4.4$ set -x
bash-4.4$ bash -c 'echo x'
+ bash -c 'echo x'
+ echo x
x
See how the bash -c 'echo x'
inherited the xtrace
option. For the options set by shopt
, it's the same but with the $BASHOPTS
variable.
It comes handy especially for the xtrace
option for debugging when you want to run a bash
script (or any command running a bash
script) and all other bash
script it may invoke, recursively with xtrace
(provided nothing does a set +x
in those scripts). If your sh
is bash
, that will also affect them, so also the system("command line")
made in other languages:
env SHELLOPTS=xtrace some-command