Issue
If I run
bash -x myscript.sh
I'll get debugging output.
But if I have a function in myscript.sh
, the code in the function is immune to -x option. It writes to output only the name of the function.
How to obtain debugging output for functions in bash scripts?
Update:
Following the ztank1013's response, I just realized that I used ksh, not bash. Seems bash has by default the functrace option enabled in my system(thanks bash-o-logist)
I am satisfied, but for the community I maintain the question open for ksh.
For script:
#!/bin/ksh
a=2
testering(){
a=3
if [ $a -eq 3 ]; then
echo lili
fi
}
if [ $a -eq 2 ]; then
echo mimi
fi
testering
exit
output of ksh -x ./testdebug.sh
is:
+ a=2
+ [ 2 -eq 2 ]
+ echo mimi
mimi
+ testering
lili
+ exit
So, for ksh, what's the trick?
(If no answer will come, the 'correct' will go to bash-o-logist.)
Solution
With bash, you can use functrace
option in your script
set -o functrace
See manpage for bash
for other debugger options.
Answered By - bash-o-logist