How do I Debug BASH Scripts?

6

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.

    
asked by anonymous 18.03.2014 / 16:08

1 answer

8

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
    
18.03.2014 / 16:17