I know that to debug script I can issue command
set -x
on the first line. The problem is that when script launches some other scripts they do not inherit this setting. So my question is whether there is some possibility to set this flag globally for shell and all subshells or for some script and all scripts launched by it?
The xtrace (–x) option causes commands in Korn shell scripts to be displayed as they are executed. This is the most useful, general debugging option. For example, tscript could be run in trace mode if invoked "ksh –x tscript".
The debugging options available in the Bash shell can be switched on and off in multiple ways. Within scripts, we can either use the set command or add an option to the shebang line. However, another approach is to explicitly specify the debugging options in the command-line while executing the script.
In Bash you can use export SHELLOPTS
. It will make all Bash subshells inherit the -x
option (as well as all the other options in SHELLOPTS!).
Example:
export SHELLOPTS
bash -x script1.sh
See bash recursive xtrace
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