In This Chapter

• Using bash Variables 613

• Using bash Operators 615

• Flow Control 619

• Shell Functions 628

• Input and Output 629

• Command-line Processing 633

• Processes and Job Control 635

Part V

Within the first two days of becoming a Linux user in 1993, I wrote my first bash script, a very kludgy effort to automate my backups. This anecdote illustrates how pervasive shell scripting is in Linux. In this chapter, I will give you a firm foundation in the basics of bash shell programming.

Why bash?

GNU's bash (Bourne Again Shell, named in punning homage to the Bourne shell and its author, Steven Bourne) is Linux's default shell. Written by Brian Fox and maintained by Chet Ramey, bash's most popular features are its rich command-line editing facilities and its job control abilities. From the programmer's perspective, bash1 s chief advantages are its customizability and the complete programming environment it provides, including function definitions, integer math, and a surprisingly complete I/O interface. As you might expect of a Linux utility, bash contains elements of all of the popular shells, Bourne, Korn, and C shell, as well as a few innovations of its own. As of this writing, the current release of bash is 2.0.3. Most Linux distributions, however, use the tried and tested 1.14 version. Nevertheless, I will cover bash version 2, pointing out features not available in earlier versions as they arise, because version 2 is much closer to POSIX compliance than version 1.

Was this article helpful?

0 0

Post a comment