Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 844
Trismegistos Avatar asked Oct 14 '13 11:10

Trismegistos


People also ask

How do I run a ksh script in debug mode?

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".

How do I debug a bash shell script?

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.


1 Answers

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

like image 103
pawamoy Avatar answered Sep 17 '22 05:09

pawamoy