Search code examples
linuxbashshelldebuggingksh

Debug bash/ksh script and subscripts


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?


Solution

  • 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