Learning the Bash Shell, 2nd Edition
Authors: Cameron Newham and Bill Rosenblatt
Publisher: O'Reilly & Associates, Inc.
Price: $29.95 US
Reviewer: Bob van der Poel
The user shell is the most-seen and used program on any UNIX system. Through the shell, a user can type commands for file maintenance, launch various application programs, and automate tedious day-to-day system administration. Some computer systems (such as Windows 95) don't come with a shell, but Linux includes a multitude. Most Linux systems have csh, sh, tcsh, ksh and bash pre-installed. bash seems to have become the standard shell for Linux.
bash, an acronym for “Bourne again shell”, is a large, complicated and powerful program. It has been developed over many years and is intended as the standard shell for GNU systems. The GNU distributions of bash come with a manual page and info-style documentation. If you are familiar with UNIX shell programming, then those will probably be all you need to get bash to do what you want. On the other hand, if you've read the man pages a few times and are still scratching your head, you may need more help.
Learning the Bash Shell, as the authors summarize in their preface, “is designed to address casual UNIX and Linux users who are just above the raw beginner level. You should be familiar with the process of logging in, entering commands, and doing some simple things with files.” After reading the book a few times, I agree; however, the usefulness of this book goes beyond simply being a beginner's tutorial. If you haven't earned all the stars on your UNIX-wizard cap, you will find it an often-used reference.
Learning the Bash Shell is a 320-page book divided into eleven chapters, five appendices and an index. It is written in an easy-to-follow style which avoids, as much as possible, the terse style of man pages and jargon. The layout and typesetting make it easy to navigate though the various explanations and examples.
The first three chapters give an overview of the functions of a shell, the extensive command-line editing capabilities of bash and the setting up of a customized environment. The section on command-line editing is one I will read a few more times—the more I understand and begin to use bash's power, the less typing I do. Considering the state of my typing ability, this is a Good Thing.
The next five chapters are certainly the most valuable—they deal with actually programming bash. All the command words, variables and built-in functions are covered. Much of this expands on material in the man/info documentation, with additional comments on when you might want to use a particular command, its history, and in some cases the suggestion that you may never need to use it. Furthermore, most of the explanations are accompanied by examples showing exactly how and when to use the command and its arguments. In good pedagogical style, the authors present a simple example; then, as the reader learns more features, the examples are revisited and expanded until one has a useful and solid shell program. Suggested exercises are included for the reader to work on in order to improve programming skills.
If you've done any programming, you know about the tedious chore of tracking down bugs in your programs. Writing scripts in bash is no different—you will have bugs, and sometimes they will be hard to find. Actually, with the arcane syntax of shell scripts, they may be very hard to find. Chapter nine will help. The standard debugging methods (lots and lots of print statements) are covered, and an extensive debugger is presented by the author. The most interesting part of the debugger is that it is actually a bash script—neat.
The final two chapters deal with the rather mundane topics of installing bash as your user shell, some security issues, and obtaining and installing bash on your own system. Fortunately, since bash comes pre-installed as the standard shell on most Linux systems, this section can be skimmed through.
The five appendices contain the expected reference lists, BNF (Barkus-Naur Form) syntax, etc.—good, useful information. Finally, the 14-page index makes it easy to use the book as a standard desktop reference.
Learning the Bash Shell was written for the 2.x version of bash; however, any features which are not supported by earlier versions of bash are noted.
Programming in a shell language like bash is quite different from using a high-level language like C. To me, it seems that bash has been kludged together by a large number of individuals who, when adding needed features, merged their preferred syntax into the shell language. The result is that the bash language can be rather convoluted, and it is easy for a beginner to get bogged down in details. For this reason alone, Learning the Bash Shell is an important tool. Be aware that writing shell scripts, especially if you have root permissions, can be dangerous to the health of your system. Fortunately, the authors warn you when their examples can compromise system integrity or security.
The examples are short enough for the user to type in, and also available from O'Reilly's FTP site—well, the authors state they are. I followed the instructions in the book and downloaded the source file. Unfortunately, the file is for the first edition of the book and misses the entire debug script. I contacted O'Reilly by e-mail and received a courteous and timely reply advising me that they would contact the book editor to track down the source. Perhaps by the time this review is in print, the correct source will be available.
We have learned to expect professional, well-written, technically correct books from O'Reilly, and Learning The Bash Shell is no exception. Writing technical reference books is always a difficult task. It is even more trying when the knowledge base of the intended audience is as varied as the book's potential readers. I think the authors have succeeded in making both an introductory primer for new users and a valuable reference for the more experienced. I highly recommend this book to anyone who wants to become more productive using bash, as well as those who wish to learn to write moderately complex shell scripts.
- Readers' Choice Awards 2014
- Handling the workloads of the Future
- Android Candy: Google Keep
- diff -u: What's New in Kernel Development
- How Can We Get Business to Care about Freedom, Openness and Interoperability?
- Synchronize Your Life with ownCloud
- Days Between Dates?
- December 2014 Issue of Linux Journal: Readers' Choice
- Non-Linux FOSS: Don't Type All Those Words!
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane