14387 shaares
5333 private links
5333 private links
The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. – Brian Kernighan, “Unix for Beginners” (1979)
When writing shell scripts, the programming logic tends to be shorter and is often contained within a single file. So there are a few built-in debugging options we can use to see what is going wrong. The first option to mention is probably the most useful too – the xtrace option. This can be applied to a script by invoking Bash with the -x switch.
$ bash -x <scriptname>
first let’s contrast -x with its opposite -v, which shows each line before it is evaluated instead of after.