Debugging bash scripts

Bash can help us to find problems in bash scripts in some ways. You don’t expect too much or gdb like environment but it has a few helpful options.

Running a shell script with -x option:

bash -x script.sh

Or you can use set builtin function in shell script:

set -x # display executed commands and arguments
set -v # display shell input lines

You can also turn off this functionality as below:

set +x