Sometimes you want to be able to debug a bash script. Usually the -x
option
will suffice but sometimes something more sophisticated is needed.
In such instances using the DEBUG trap is often a good choice.
Attached to this gist is a example script to demonstrate how such a thing would work.