Learning the Bash Shell, 2nd Edition

December 1st, 1998 by Bob van Poel in

bash, an acronym for “Bourne again shell”, is a large, complicated and powerful program.
Your rating: None
  • Authors: Cameron Newham and Bill Rosenblatt

  • Publisher: O'Reilly & Associates, Inc.

  • E-mail: info@oreilly.com

  • URL: http://www.oreilly.com/

  • Price: $29.95 US

  • ISBN: 1-56592-347-2

  • 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.

Bob van der Poel started using computers in 1982 when he purchased a Radio Shack Color Computer complete with 32KB of memory and a cassette tape recorder for storing programs and data. He has written and marketed many programs for the OS9 operating system. He lives with his wife, two cats and Tora the wonder dog on a small acreage in British Columbia, Canada. You can reach him via e-mail at bvdpoel@kootenay.com. If he's not too busy gardening, practicing sax or just having fun, he'll probably send a prompt reply.

__________________________


Special Magazine Offer -- 2 Free Trial Issues!
Receive 2 free trial issues of Linux Journal as well as instant online access to current and past issues. There's NO RISK and NO OBLIGATION to buy. CLICK HERE for offer

Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.

Sorry, offer available in the US only. International orders, click here.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

linux

On October 2nd, 2007 enigma downloads (not verified) says:

before kept architectures code each me and IOW, again maintenance? has which why justifies arch you date the problem by what exceptions? have use extra up done we are working dependent to work not it Tell So need driver any can existing maintainer. mechanisms be for all . Bye.

linux

On October 2nd, 2007 download enigma free mp3 (not verified) says:

Who is Mark Lord? . Best regards.

Bash Programming

On February 3rd, 2007 Mike (not verified) says:

Nice bash tutorial at

http://www.gnulamp.com/bashprogramming.html

http://www.gnulamp.com/awk.html

On February 8th, 2007 Anonymous (not verified) says:

awk tutorial at:

http://www.gnulamp.com/awk.html

Post new comment

Please note that comments may not appear immediately, so there is no need to repost your comment.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.

More information about formatting options

Featured Videos

The October 9, 2008 edition of Linux Journal Live! Associate Editor, Shawn Powers, and Kyle Rankin, "Hack and /" columnist and author of Knoppix Hacks, Linux Multimedia Hacks, Knoppix Pocket Reference and others, discuss Linux distributions.

The October 2, 2008 edition of Linux Journal Live! Associate Editor, Shawn Powers, and Steven Evatt, Online Development manager for The Houston Chronicle discuss surviving disaster with Linux.

From the Magazine

November 2008, #175

There aren't many numbers that put the US national debt to shame, but here's one: 1,100,000,000,000,000. What's that? That's how many floating-point operations per second the Roadrunner supercomputer at Las Alamos can perform. That's about 100 FLOPS per dollar of US debt (unfortunately, the debt is winning the second derivative race). Read the article about Roadrunner in this month's High Performance Computing issue of LJ.

Along with that, find out how to program the Cell processor and how to use CUDA with your NVIDIA GPU. Also in this issue: Mr HandS (aka Kyle Rankin) gives us a few tips on using Compiz, Chef Marcel shows you how to get blogging off your plate quicker, Mick Bauer talks about Samba security, Dan Sawyer interviews Cory Doctrow and Doc talks about how information technology can affect democracy and fix the national debt (just kidding about that last part). That and more for your reading pleasure in this month's Linux Journal.

Read this issue