Many books are available on shell programming, and I own copies of just about all of them. However, there are only two that I remove from the shelf any more often than once in a blue moon. The first is the venerable The UNIX Programming Environment by Kernighan and Pike. The second is Portable Shell Programming by Bruce Blinn.
Blinn's book focuses almost exclusively on the Bourne shell, although occasionally he notes some features of the Korn, C and other popular shells when distinctions in capability or differences in the execution of the same code crop up. This is a natural decision since the it is generally acknowledged that Bourne type shells (which include the Posix shell, Bash, and Ksh) are better form programming than C type shells (which includes Tcsh), and because the first word of the title is "Portable", and only the Bourne shell, or a functional equivalent, is guaranteed to be available on every flavor of UNIX.
The book steps through the functions of the shell explaining the shell syntax, built-in commands, and I/O. These sections are all very solidly written and provide a detailed explanation of each command and all its features, many of which were not available at the time of K&P. In addition to emphasizing simplicity for the sake of portability, Blinn also attends to performance considerations and suggests general style guidelines that are aesthetically and functionally sound.
After a brief chapter on interpreting command line options in shell scripts, Blinn turns to an extended discussion of the use of sed as a filter for these scripts. The explanation and uses of sed are compact, although they provide enough information to cover the vast majority of the situations for which it is commonly used. A noted absence from the book is that there is no more than passing coverage of the awk programming language, which solves several shell problems more elegantly than other UNIX commands. The complete shell programmer will want to obtain a separate reference to this programming language.
The next several chapters cover shell utilities, including the important and mysterious "IFS" variable, shell functions, and examples of complete and marginally complex shell scripts. The functional explanations are all quite good, and the sample scripts are often useful themselves, and they do a good job of illustrating the use of the concepts presented in preceding chapters.
The next two chapters, on debugging and specific portability issues, are very well thought out and are far and away the best sources of this information I have seen in print. This information is excellent and even an expert shell programmer will almost certainly find something of significant value here. These chapters are followed by a list of common problems and resolutions that shell programmers commonly face. This information is also extremely useful, and it's likely that they will impart significant understanding to most readers. The book ends with a comparison of shells and a summary of the Bourne shell syntax.
The only major downside to this book is it's price. For its size, $40 seems a bit steep to me, but given the quality of the material in the book, it's really quite a bargain. I recommend that every shell programmer should own Portable Shell Programming along with their well worn copy of K&P. I don't think it's necessary to purchase any other books on the topic.
The finest advanced book on shell programming I've read, Portable Shell Programming belongs on every shell programmer's bookshelf despite the relatively steep price for its size. The beginner should read Kernighan and Pike's The UNIX Programming Environment first, but these two books together represent all the shell programming information one is likely to need.
Click here to return to the index of reviews.