I'm having some problems with some scripts in bash, about errors and unexpected behaviors. I would like to investigate the causes of the problems so I can apply fixes. Is there a way I can turn some kind of "debug-mode" for bash, to get more information?
Bash – How to debug a bash script
bashdebugging
Best Answer
Start your bash script with
bash -x ./script.sh
or add in your scriptset -x
to see debug output.Additional with
bash
4.1 or later:If you want to write the debug output to a separate file, add this to your script:
See: https://stackoverflow.com/a/25593226/3776858
If you want to see line numbers add this:
If you have access to
logger
command then you can use this to write debug output via your syslog with timestamp, script name and line number:You can use option
-p
oflogger
command to set an individual facility and level to write output via local syslog to its own logfile.