How can I debug bash scripts? In DOS from Microsoft I can use the @echo ON and @echo OFF. I would like to use something similar on Linux.
How can I debug bash scripts? In DOS from Microsoft I can use the @echo ON and @echo OFF. I would like to use something similar on Linux.
Use the following:
sh -x script [arg1 ...]
bash -x script [arg1 ...]
This allows you to do a trace of what is running.
Another useful option is -n which stands for no execution and -v for verbose mode . It is useful to combine these parameters to further facilitate your bash shell DEBUG when you invoke the prompt.
If you want to control trace from within the Script in specific code blocks use:
set -x
to turn on the trace . To turn off trace use:
set +x