I'm having some problems with some scripts in bash about errors and unexpected behavior I'd like to look for the causes of the problems so i can apply solutions Is there any way to turn a debug mode for bash to get more information?
Start your bash script with
bash -x ./script.sh or add in your script
set -x to see debug output.
bash 4.1 or later.
If you want to write the output of debug in a separate file add this into your script
exec 5> debug_output.txt BASH_XTRACEFD="5"
Add this if you want to see line numbers
If you have access to
loggercommand then you can use this to write debug output via your syslog with timestamp, script name and line number:
#!/bin/bash exec 5> >(logger -t $0) BASH_XTRACEFD="5" PS4='$LINENO: ' set -x # Place your code here
You can use option
logger command to set an individual facility and level to write output via local syslog to its own logfile.