Pro Bash Programming

Scripting the Linux Shell

By Chris Johnson

Pro Bash Programming Cover Image

The bash shell is a complete programming language, not merely a glue to combine external Linux commands. By taking full advantage of shell internals, shell programs can perform as snappily as utilities written in C or other compiled languages.

Full Description

  • ISBN13: 978-1-4302-1997-2
  • User Level: Intermediate to Advanced
  • Publication Date: October 18, 2009
  • Available eBook Formats: EPUB, MOBI, PDF
  • Print Book Price: $34.99
  • eBook Price: $24.99
Buy eBook Buy Print Book Add to Wishlist

Related Titles

Full Description

The bash shell is a complete programming language, not merely a glue to combine external Linux commands. By taking full advantage of shell internals, shell programs can perform as snappily as utilities written in C or other compiled languages. And you will see how, without assuming Unix lore, you can write professional bash 4.0 programs through standard programming techniques.

  • Complete bash coverage
  • Teaches bash as a programming language
  • Helps you master bash 4.0 features

What you’ll learn

  • Use the shell to write new utilities and accomplish most programming tasks.
  • Use shell parameter expansion to replace many external commands, making scripts very fast.
  • Learn to avoid many common mistakes that cause scripts to fail.
  • Learn how bash’s readline and history libraries can save typing when getting user input.
  • Learn to use features new to bash 4.0.
  • Build shell scripts that get information from the Web.

Who this book is for

Beginning Linux and Unix system administrators who want to be in full command of their systems.

 

Table of Contents

Table of Contents

  1. Hello, World! Your First Shell Program
  2. Input, Output, and Throughput
  3. Looping and Branching
  4. Command-Line Parsing and Expansion
  5. Parameters and Variables
  6. Shell Functions
  7. String Manipulation
  8. File Operations and Commands
  9. Reserved Words and Builtin Commands
  10. Writing Bug-Free Scripts and Debugging the Rest
  11. Programming for the Command Line
  12. Runtime Configuration
  13. Data Processing
  14. Scripting the Screen
  15. Entry-Level Programming
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

Please Login to submit errata.

On page 15:
The example code for redirection with exec command is missing between "You can use the exec command to redirect the I/O streams for the rest of the script or until it's changed again" and "All standard input will now go to the file tempfile [..]"

On page 50:

The bottom of page 50 introduces the ${var%%PATTERN} form of parameter expansion.
This section's example script contains an error.
Its output is incorrect.
The script actually produces a result of :T: instead of :t:.

the example script:
$ var=Toronto
$ sa "${var%%o*}"
:t:

:t: should be :T:

The sa script is defined in Listing 4-1 on page 29 and reads as follows:
pre=:
post=:
printf "$pre%s$post\n" "$@"

On page 70:
The _revstr() function does not work properly.
I believe the reassignment line in the while loop should be:
_REVSTR=${var%"$temp"}$_REVSTR