scmrak's Full Review: Dave Taylor - Wicked Cool Shell Scripts: 101 Scrip...
As more and more of the technological literati wander away from the World of Windows and Apple Acres into the Land of Linux, long-time UNIX geeks have been observed clapping their (our?) hands in glee. Finally, at long last, the "world's finest OS" is getting its due. It's faster - lacking the overhead built into those squabbling commercial systems by years of high turnover and internecine politics - and every bit as stable. More stable, by an order of magnitude, than some Windows versions. Take ME... no, take it, please!
Of course, there will always be those who run screaming from the room when confronted by a system prompt, a curiously large proportion of whom seem comfortable with error messages delivered with icons in the shape of little cartoon bombs. But for people to whom commands such as "DIR" aren't frighteningly arcane, the simple, open user interface of a Linux-driven system can be a veritable playground. One of the guys who plays there every day is a fellow named Dave Taylor. An unapologetic geek, Taylor is one of the folks to whom "hack" is a positive word, meaning "an interesting, inventive tool." Taylor likes to hack around in Linux (usually the underpinnings of Mac OS X), and he's shared some of the toys he's created over the years in No Starch Press's Wicked Cool Shell Scripts.
A Shell Script, for those of you not in the know, is a set of commands collected in an executable file. When it's run, the script fires off those commands for you in a transparent manner. All you have to do is issue the command and, in some cases, values or file names, and the script communicates your whims to the Linux operating system. Presto! You have your answer or your new file or your information in a single step instead of having to remember several different commands and how to configure them.
Unlike a graphical user interface, all these scripts are textual - you run them in a terminal window by typing in the command and the input, and the answers appear in the same terminal window. You may not see the glitzy high-tech look you're used to, but scripts tend to run a lot faster and use far less in terms of system resources. Too, given a little thought, you can get a script to do just about anything you need - not as pretty, perhaps, but probably faster.
Taylor's Wicked Cool Shell Scripts come in 101 flavors, from simple mathematical calculations (converting temperatures to and from degrees K, C, and F) to scraping information off the internet movie database. The scripts are collected in a dozen classifications:
The Missing Code Library (scripts 1-13) contains building blocks for more powerful scripts; things like validating date formats, locking and unlocking files, and the like. Most of these scripts are rather boring because they don't do anything "fun."
Improving on User Commands (14-22) expands on the basic commands you can enter at the system prompt. There's one script to help die-hard DOS people use the DIR command instead of "ls" (I remember having set up an alias for a similar problems when switching from VMS to UNIX many years back). Other scripts access system utilities you may not have known you had - displaying the current time in another time zone, "prettifying" your results from a man -k command - or summarizing information about directory contents with a single command.
Creating Utilities (23-30) gives you access to some of the tools you're used to with a GUI: a calculator (which accesses a little-known UNIX single-line calculator utility), a reminder facility, a spell-checker, calculators (temperature, loan payment). Not pretty versions, mind you, but useful.
Tweaking* UNIX (31-38) does some things I'd never considered doing - but they're good ideas: guaranteeing maximum compression for a file (comparison of the "compress" utility, gzip, and other compression algorithms), and displaying your file with line numbers.
System Administration: Managing Users (39-48) kind of leaves me cold, since I'm not a SysAdmin except on my Linux-enabled laptop (where no one else ever goes). If you don't have access to utilities like the Solaris AdminTool, though, or you're running a stripped version of Linux unlike my Red Hat 9.0, you might find this useful. You can do things like check for violation of disk quota, disuser people, and the like.
System Administration: System Maintenance (49-57) contains more handy little tools for SysAdmins on UNIX systems. Most of the utilities are for managing cron jobs and making certain that the system is properly backed up. Even people on stand-alone systems will find these useful.
Web and Internet Usage (58-68) has some oddball utilities like scraping information from various websites - IMDb (Internet Movie Database), stock quotes, currency exchange rates, BBC news, and Weather.com. These scripts can be run from the command line or set to run from a cron job. All have the typical web-scraping caveat: if the website changes data format, you'll have to rebuild the script to match.
Webmaster Hacks (69-76) could be useful if you're operating your own website and want to change your server OS over to Linux. You can create a guestbook, a page-hit counter, and the like.
Web and Internet Administration (77-83) is mainly for handling web transactions cleanly - keeping mirrors up-to-date automatically, managing passwords, finding broken links.
Internet Server Administration (84-92) pretty much assumes you're running your website with an Apache server (of course you are). There are scripts for plumbing the depths of the access and error logs, capturing keywords when users find your site via search engine, and the like.
Mac OS X Scripts (93-98) mainly deals with the deficiencies and quirks of Apple's implementation of Linux - adding new users, fixing given commands, and the like.
Shell Script Fun and Games (99-101) is the inevitable games: a state capitals quiz, a version of "hangman," and an anagram game.
The Scripts are all written for the Bourne shell (c and k shell users get severely dissed in the introduction). Me, I like the similarity of commands between the c programming language and c shell, but Taylor and his cronies don't. All the scripts are also POSIX-compliant, a potential downer for Solaris users, but Taylor provides a fix.
Most of the scripts are only ten to thirty lines long - after all, they simply access existing UNIX programs in a preset order. Taylor introduces them by stating a purpose and possible usages, then includes the commented code. The code is followed by a discussion of what it actually does and "How it Works," and descriptions of both the input and output to the script. Most scripts also have suggested "hacks" - meaning improvements, such as ways to prettify the output or to make the script more powerful.
Many of the later scripts call scripts that - supposedly - you wrote from earlier in the book and saved in your personal toolbox. Don't despair, the official website for the book contains all scripts in downloadable format, plus several others that didn't make the final cut (including more games). There are also errata and comment sections for people who can't get a particular script to run under one of the many slightly different flavors of UNIX out there.
You'll Benefit from Wicked Cool Shell Scripts if you like to make your own tools and you've made the jump to UNIX/Linux. If you're perfectly content to let Microsoft or Apple do everything for you, then you probably won't be interested - just remember that these scripts access the OS directly, without one, two, or more layers of overhead between you and the processor. That means they're faster and more powerful. What's not to like about that?
Many of the tools are pretty simplistic, doing tasks that can easily be performed with the GUI applications that your copy of a commercial Linux (or UNIX) OS came with. But, like any snippet of code, any script can act as a "go-by" or template for building your own, more complex script to perform a task for which you have no tools. The downside of Taylor's scripts is that the explanations presume some familiarity - in more than one case, a lot of familiarity - with the command that they're running. Even after ten years of frolicking in the UNIX world, I was confused my a few of his implementations. There's virtually nothing in terms of explaining the sometimes strange syntax of the commands, and when entering the scripts by hand I frequently found myself wondering if spaces and other formatting arrangements were a Taylor programming practice or required by the OS. I still don't know.
This one's useful for confirmed geeks, but beginners will want to get a crash course in writing scripts first, and I don't know of any offhand. Taylor alludes to courses in basic scripting on the web, but a cursory glance via Google didn't' turn up any for me. So caveat emptor, wannabe UNIX geeks.
* note Taylor's correct spelling of "tweak." The Grammar Curmudgeon is gratified.
Epinions.com periodically updates pricing and product information from third-party sources, so some information may be slightly out-of-date. You should confirm all information before relying on it.