Work the Shell - When Is “Good Enough” Good Enough?

Shell scripting and obsessive-compulsive perfectionism is almost a contradction in terms.

Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

While shell scripts are

A. T. Young's picture

While shell scripts are indeed great for fast prototyping, they're equally useful for mission-critical production code. Look at the scripts that installed your system, and the ones that bring everything up each time you boot.

In addition, even large, complex applications can be written as shell scripts -- especially with the fast hardware we have these days. A few years ago, I got tired of continually re-writing a big nonlinear damped-least-squares program that I'd been using for decades, every time a new problem came up. I noticed that the changes needed were so mechanical that I could let the machine do that work for me. So I now have a 2500-line shell script that looks at the data, infers its format, asks the user a few questions (like what the model is to be fitted), and collects the necessary pieces to form the source code for the program, compiles it, and then executes the program. Ten years ago I'd never have dreamed of putting a compilation inside a shell script, but in fact it all proceeds smoothly, and you hardly notice the little momentary pause while the compilation takes place.

While lots of shell scripts are indeed throwaways that need only to be barely good enough for one-time use, a surprising number turn out to be things you find yourself using again and again -- often in spite of your original intentions. So I've found it pays, in the long run, to take the time to add enough comments to document the code for the time a year from now when I find myself looking at it cold again.

I agree that optimizations are things you only do when you find the thing runs too slowly, though. Often, this is best done by finding the slow part of the script and writing just that one bit as a compiled program in your favorite language, leaving the rest of the procedure as a shell script.

Good enough

martyskitch's picture

Great article and as I tell my kids when they are doing homework "Prefection is the enemy of good enough".