Shell Scripting Recipes
Purchase from Amazon.ca, Amazon.com Amazon.co.uk or E-book
Reviews
Amazon.com
SitePoint UnixReview.com Duffbert

The Scripts (tar.gz)

Errata

Shell Scripting Recipes: A Problem-Solution Approach

by Chris F.A. Johnson

Apress, 2005

448 Pages

POSIX shell scripts offer a means for creating powerful and portable applications. When coupled with utilities such as grep, sed, and the AWK programming language, the shell is more than adequate for resolving a wide range of programming tasks. I wrote this book to demonstrate these capabilities and help you to learn shell scripting by providing hundreds of examples.

The opening chapter sets the stage for this collection, introducing many Unix shell features and helping familiarize you with the syntax in many of the examples. The following chapters present scripts and shell functions ranging from one-liners to multipage programs. These scripts and functions convert DOS-based text files to Unix and vice versa, maintain financial ledgers (which can be easily imported to a spreadsheet program), extract information from web pages, and more. To facilitate code reuse, the book offers numerous function libraries that you can use to build even more programs quickly.

Some scripts in this book are taken from the hundreds I've written over the past 15 years, while others were written specifically for this book. I carefully selected each not only to demonstrate the breadth of problems that can be solved with shell scripts, but also to illustrate as many scripting techniques as possible.*

I hope this book will help you solve the many problems illustrated by these scripts, and also encourage and help you to write your own.

Ch.Title
1The POSIX Shell and Command-Line Utilities
2Playing with Files: Viewing, Manipulating, and Editing Text Files
3String briefs
4What's in a Word?
5Scripting by Numbers
6Loose Names Sink Scripts: Bringing Sanity to Filenames
   The Naming of Files is a serious matter,
        This isn't just one of your Usenet flames;
   You may think at first it doesn't much matter
   But I tell you, a file should have a SENSIBLE NAME.

                                       (with apologies to T. S. Eliot)
7Treading a Righteous PATH
8The Dating Game (Sample chapter PDF or HTML)
9Good Housekeeping: Monitoring and Tidying Up File Systems
10POP Goes the E-Mail
11PostScript: More Than an Afterthought

This crossword grid was created by the ps-grid script in Chapter 11.

This puzzle's source file (in AcrossLite text format) can also be found in that chapter.
ACROSS
1 The woman will, for outer covering (5)
4 Host reformatted after a thousand bugs (5)
5 Collection of data by a random beam (5)

DOWN
1 Frodo's companion has degree in file services (5)
2 Go in to get key for execution (5)
3 In a real OS, symbolic type of compression (5)

12Screen Manipulation:
13Backing Up the Drive
14Aging, archiving and deleting files
15Covering All Your Databases
16Home on the Web
17Taking Care of Business
18Random Acts of Scripting
   "The generation of random numbers is too important
    to be left to chance."

                    Robert R. Coveyou, Oak Ridge National Laboratory
19A Smorgasbord of Scripts
20Script development management

Detailed Table of Contents
Shop at Amazon.ca!

* There are some shell scripting techniques that are not (or very little) used in this book:

  • Here documents are not used at all.
  • typeset and its bash cousin declare are not part of the POSIX specification and are not used in this book; local may be used in bash-only scripts
  • trap is used very sparingly
  • select is never used; I find it clumsy to use, and writing a simple menu, with vastly more flexibility, is a trivial task in a shell script
  • Tracking mouse events is not covered
  • Use of cursor and function keys is not addressed
Use no style sheet
Use alternate style sheet
Use default sheet