Portable Shell Programming

Author: Bruce Blinn
List Price: $49.93
Our Price: Click to see the latest and low price
ISBN: 0134514947
Publisher: Prentice Hall PTR (19 October, 1995)
Edition: Paperback
Sales Rank: 86,805
Average Customer Rating: 4.59 out of 5

Buy now directly from Amazon.com - Purchase this book, safely and securely from the largest book dealer on the Internet, Amazon.com

Customer Reviews

Rating: 4 out of 5
excellent
If you've done any intoductory shell programming at all, this book will get you started in more serious shell programming efforts. I only gave this book 4 stars although it really deserves more, because it may not live up to the expectations of some readers.

Only the Bourne shell is covered, because it's the most portable. It covers all the basics and many advanced issues. The authors philosphy is to teach by example, and this book is full of examples and sample code.

The first half of the book is a down and dirty "How To by Example." The examples are general enough and well enough documented that the use for the syntaxes described remains clear in the readers mind. The second half of the book contains some sample shell utilities. These are shell programs that were written to mimmick or epxpand on functionality of common UNIX commands. I found the first half of the book to be the most useful over time.

Some explanations may be a bit terse for brand new shell prgrammers. Awk is covered in much detail at all, although there are some very nice examples of using sed. All in all this is the best shell programming reference I've seen.


Rating: 4 out of 5
Great Shell Programming Intro
The author starts off with the assumption that the reader is technically savvy but has no knowledge of shell scripting. This means that the first chapter necessarily covers basic
syntax such as creating a script file, comments, file name expansion, quotes, control structures, pipes, etc. I found this chapter extremely useful for reviewing the basic building blocks that all shell scripts tend to share. This will be a valuable chapter for someone brand new to shell scripting or Unix-style operating systems. The 4 pages covering quoting was the most lucid coverage I have yet found.

Variable are covered comprehensively in Chapter 2. This chapter covers all the ways of declaring, initializing, assigning and passing variables. It also covers the Borne shell special variables, such as $?, $$, etc. I learned some new techniques for handling uninitialized variables using special Borne shell syntax, such as "${variable:?message}". This statement causes the script to print out the "message" and then terminate if the "variable" is not initialized.

The author next covers shell functions and built-in commands available in Borne shell. The 3 pages on shell functions is adequate to illustrate function syntax. The author also does an adequate job of examining function parameters, variables in functions, strategies for reusing functions and the different effects from executing a function in the current shell versus a subshell. The rest of the book shows numerous examples of functions, so the lack
of function examples here is acceptable. Next the author introduces the important built-in
commands such as : (null), . (dot), eval, exec, read, test, wait, and many others. All of the non-obvious commands have an example or two. Most of these commands are also used extensively in the remainder of the book.

The point of most shell scripts is to manipulate files, so I consider the material in Chapter 4 crucial. This chapter does a fine job of explaining the file descriptors (0,1,2) and redirection of input and output. The author then discusses opening, writing, reading,
closing and truncating files. Finally, "here" documents are covered. This is a nifty feature of Borne shells which allow the creation of "inline" documents.

Borne shells usually depend on the fact that they are running on a Unix-like system. In other words, most shell scripts interface with the operating system. Chapter 5 details how Bourne scripts interact with the environment they are running in. Coverage includes Environment Variables, child versus parent environments, getting user and system information, using signals, and, finally, remote commands. The coverage is not comprehensive, nor could it be. It would take volumes to comprehensively cover the UNIX environment in relation to shell scripts. With that said, the author presents a respectable subset of the most important topics.

The next short chapter first reviews the UNIX command line conventions, e.g. "command [options] [parameters]". The author then discusses the getopt(s) commands for parsing command line parameters and what to do when these commands are not available.

Filters are commands that get their data from the standard input, perform some transformation on the data, and then write the data to the standard output. More than one filter can be strung together to perform very complex transformations. This chapter presents an introduction to this important topic. The tools illustrated are pipes, sed and awk. This chapter, again, only presents an introduction. But the number of examples is impressive and so is the categorization. With this chapter, Chapter 8 and the man pages for sed and awk, a reader will be in a position to infuse his shell scripts with considerable power.

Chapter 9 and 10 are the culmination of the previous 8 chapters. Chapter 9 provides a library of shell functions that I found highly instructive. The list of functions are: CheckHostname, Clear, DownShift, FullName, GetYesNo, IsNewer, IsNumeric, IsSystemType, Prompt, Question, StrCmp, and, finally, SystemType.

The author presents an assortment of shell scripts that are written to be both instructive and useful. As with the functions in Chapter 9, I found these to be highly instructive. The list of scripts are: Cat, DirCmp, Kill, MkDir, Shar, Wc, addcolumn, dircopy, findcmd, findfile, findstr, hostaddr, and, finally, ptree.

No programming language guide would be complete without the obligatory coverage of debugging. This is an area of personal interest to me, because my experience in the industry has taught me that few programmers leave the university with adequate debugging skills. The art of debugging boils down to a set of heuristics for reproducing or capturing an error, narrowing down the potential causes to a manageable set of candidates, and then progressively simplifying until the exact cause of the problem can be understood and corrected. This chapter will not teach the reader to be a competent debugger. The chapter does illustrate common pitfalls that shell scripts contain. It also discusses the basic elements in tracing through a script and even touches on shell scripting style as a tool to reduce bugs. All good, common sense information.

Considering the title of the book, it would be expected that there would be a chapter on portability. This chapter presents some of the best material I have seen assembled on writing portable shell scripts. The author discusses System V versus BSD, subsets of commands, abstraction, locating commands and files, shell features, issues with a number of specific commands, and file and path names. If you are writing production scripts that may be shipped in a heterogeneous environment, this is required reading.


Rating: 5 out of 5
Five stars for usefulness
Bruce Blinn has written a very useful, highly practical shell programming book.

I am working my way through the book but even after a chapter or two I have started to apply the priceless nuggets I was able to glean.

If you work in a Un*x environment and need to script tedious tasks to allow you more time to get on with the fun stuff, then this will help you.

It is well written and as easily understood as you can reasonably expect when you consider the arcane subject matter.

Similar Products

· Mastering UNIX Shell Scripting
· Unix in a Nutshell: A Desktop Quick Reference for SVR4 and Solaris 7 (3rd Edition)
· Unix Power Tools, Third Edition
· Unix Shell Programming, Third Edition
· sed & awk (2nd Edition)

Return To Main Computer Book IndexSearch Our Entire Computer Book Catalog