Classic Shell Scripting - Arnold Robbins [6]
Chapter 5
This chapter shows several small scripts that demonstrate combining simple Unix utilities to make more powerful, and importantly, more flexible tools. This chapter is largely a cookbook of problem statements and solutions, whose common theme is that all the solutions are composed of linear pipelines.
Chapter 6
This is the first of two chapters that cover the rest of the essentials of the shell language. This chapter looks at shell variables and arithmetic, the important concept of an exit status, and how decision making and loops are done in the shell. It rounds off with a discussion of shell functions.
Chapter 7
This chapter completes the description of the shell, focusing on input/output, the various substitutions that the shell performs, quoting, command-line evaluation order, and shell built-in commands.
Chapter 8
Here we demonstrate combinations of Unix tools to carry out more complex text processing jobs. The programs in this chapter are larger than those in Chapter 5, but they are still short enough to digest in a few minutes. Yet they accomplish tasks that are quite hard to do in conventional programming languages such as C, C++, or Java©.
Chapter 9
This chapter describes the essentials of the awk language. awk is a powerful language in its own right. However, simple, and sometimes, not so simple, awk programs can be used with other programs in the software toolbox for easy data extraction, manipulation, and formatting.
Chapter 10
This chapter introduces the primary tools for working with files. It covers listing files, making temporary files, and the all-important find command for finding files that meet specific criteria. It looks at two important commands for dealing with disk space utilization, and then discusses different programs for comparing files.
Chapter 11
Here we tie things together by solving an interesting and moderately challenging task.
Chapter 12
This chapter uses the problem of doing spellchecking to show how it can be solved in different ways. It presents the original Unix shell script pipeline, as well as two small scripts to make the freely available ispell and aspell commands more usable for batch spellchecking. It closes off with a reasonably sized yet powerful spellchecking program written in awk, which nicely demonstrates the elegance of that language.
Chapter 13
This chapter moves out of the realm of text processing and into the realm of job and system management. There are a small number of essential utilities for managing processes. In addition, this chapter covers the sleep command, which is useful in scripts for waiting for something to happen, as well as other standard tools for delayed or fixed-time-of-day command processing. Importantly, the chapter also covers the trap command, which gives shell scripts control over Unix signals.
Chapter 14
Here we describe some of the more useful extensions available in both ksh and bash that aren't in POSIX. In many cases, you can safely use these extensions in your scripts. The chapter also looks at a number of "gotchas" waiting to trap the unwary shell script author. It covers issues involved when writing scripts, and possible implementation variances. Furthermore, it covers download and build information for ksh and bash. It finishes up by discussing shell initialization and termination, which differ among different shell implementations.
Chapter 15
In this chapter we provide a cursory introduction to shell scripting security issues.
Appendix A
This chapter describes how to write a manual page. This necessary skill is usually neglected in typical Unix books.
Appendix B
Here we describe the Unix byte-stream filesystem model, contrasting it with more complex historical filesystems and explaining why this simplicity is a virtue.