Washington Apple Pi

A Community of Apple iPad, iPhone and Mac Users

Wicked Cool Shell Scripts: A Review

© 2005 Lawrence I. Charters

Washington Apple Pi Journal, reprint information

Wicked Cool Shell Scripts: 101 for Linux, Mac OS X and other Unix Systems has a title that, all by itself, is revolutionary. Since the very beginning, Unix has dominated the Internet and the telecommunications world. The Mac, even though it was one of the first computers to ever include networking as a standard feature, was long relegated to the edges of the Internet mainstream. But today Mac OS X is the most successful, most widely deployed version of Unix in history, and new Unix books place it front and center.

On the other hand, Unix scripting isn’t necessarily front and center in the world of Mac users. Unless you start playing with the Terminal, Mac OS X does a splendid job of hiding the Unix core under a bright and beautiful Mac cover. But once you start using Terminal, there is no escape: scripting is one of the pillars on which Unix is built.

Wicked Cool Shell Scripts cover

In its simplest form, a script is a series of stored instructions. You store a script as a file and trigger the script when you want it to execute those instructions. Scripts can be as simple as giving users a personalized greeting when they log in, or as complicated as an advanced diagnostic utility formed of a number of separate utilities but bound together and given coherence through scripting.

Author Dave Taylor is an excellent guide into the world of scripting, author of several previous books on Unix and of several programs included in the BSD 4.4 Unix distribution. His approach is direct: he doesn’t waste time telling you why scripting is a good idea or editorializing about other subjects, but dives right in, showing how to script various user tasks, create utilities to do housekeeping chores, and even ventures into Web and Internet functions and chores. Each script is broken down into parts so you can see what the pieces do on their own, and then combined into more complex structures.

If you are an experience Mac user, the first thing you will notice is that many of the scripts are unnecessary in Mac OS X. On a Mac, you can create user accounts, control directories, change permissions, and even view logs without once venturing into the Unix shell. This is, believe it or not, a huge advantage: you can create a script to do a task, and easily check its validity simply by performing the same task or series of tasks using the Mac interface.

Several of the scripts, for example, essentially recreate the capabilities of Apple’s Network Utility, which can be found in Applications > Utilities. If you follow along and build the scripts, not only do you learn a great deal about scripting, but you also learn a great deal about the strengths and weaknesses of Network Utility.

Virtually all the scripts seem like they’d work in Mac OS X, Linux, or almost any other version of Unix. They all assume you are working with the bash shell (bash is the default shell in Mac OS X 10.3), but otherwise have no particular demands other than accurate typing and paying attention to subtleties.

One chapter is entirely devoted to Mac OS X scripts. This is an intriguing inclusion, since virtually all the tasks can be done in Mac OS X without scripting. One advantage to building the scripts, however, is the ability to do these functions – adding users, launching programs, and doing funky tricks with iTunes – remotely.

As an introduction to Unix scripting, especially for Mac users, the book is hard to beat. It doesn’t spend a great deal of time talking about the larger world of Unix, or of scripts, or of programming. Instead, it is a neatly encapsulated domain of knowledge, enough to get you started without scaring you off with esoteria. Recommended.

David Taylor, Wicked Cool Shell Scripts: 101 Scripts for Linux, Mac OS X, and Unix Systems. No Starch Press, 2004. xx, 341 pp. $29.95. ISBN 1-59327-012-7

http://www.nostarch.com/