#13 Debugging Shell Scripts

Although this section does not contain a true script per se, it's a good place to spend a few pages talking about some of the basics of debugging and developing shell scripts, because it's a sure bet that bugs are going to creep in!

The best debugging strategy I have found is to build scripts incrementally. Some script programmers have a high degree of optimism that everything will work right the first time, but I find that starting small, on a modest scale, can really help move things along. Additionally, liberal use of echo statements to track variables, and using the -x flag to the shell for displaying debugging output, are quite useful. To see these in action, let's debug a simple number-guessing game.

The ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.