Bash has a sometimes-useful feature whereby if you turn on the "-x
" option (I believe the symbolic name is xtrace
), Bash outputs each line of script as it executes it.
I know of two ways to enable this behavior:
- In the script itself, say
set -x
- On the command line, pass the
-x
option to Bash.
Is there any way of turning this option on via environment variables?
(In particular, I'm not invoking Bash myself, so I can't pass any options to it, and the script of interest is inside a compressed archive which I don't really feel like rebuilding. If I could set an environment variable, it would presumably be inherited by all child processes...)
The manpage says something about
BASHOPTS
, but when I try it Bash says that's read-only. (Thanks for not mentioning that in the manpage.)Similarly,
SHELLOPTS
also seems to be read-only.You can select which FD is used with
BASH_XTRACEFD
. But I still need to turn tracing on in the first place.
set -x
in the terminal and run the script?set -x; ./script.sh ; set +x
./script.sh
is a child process, right?bash
5.0.7, it would trace the call to the shell script, but tracing would not be turned on inside the script itself, i.e. the shell option would not be inherited by the script.