Debugging Shell Scripts
If you’ve ever written a beautiful looking script, only to be disappointed when it doesn’t work properly, don’t feel alone. This happens to all of us, and even happened to me a few times when I was creating scripts for this book. (I know, shocking, right?)
The debugging process should begin the moment that you begin to design your code. Put careful thought into the design, test each portion as you write it, and—for goodness’ sake—use a text editor with color-coded syntax highlighting. (That color highlighting will prevent you from making a multitude of typographical errors.)
Topics in the chapter include:
- Understanding common scripting errors
- Not Enough Quoting
- Creating a Wild Loop
- Using shell script debugging tools and techniques
- Using
echo
Statements - Using
xtrace
for Debugging - Checking for Undefined Variables
- Checking for Errors with the
-e
Option
...