Flylib.com

Books Software

 
 
 

Intended Audience

 < Day Day Up > 

Intended Audience

This book 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 simple things with files. Although Chapter 1 reviews concepts such as the tree-like file and directory scheme, you may find that it moves too quickly if you're a complete neophyte. In that case, we recommend the O'Reilly handbook, Learning the UNIX Operating System , by Jerry Peek, Grace Todino, and John Strang.

If you're an experienced user , you may wish to skip Chapter 1 altogether. But if your experience is with the C shell, you may find that Chapter 1 reveals a few subtle differences between the bash and C shells .

No matter what your level of experience is, you will undoubtedly learn many things in this book that will make you a more productive bash user—from major features down to details at the "nook-and-cranny" level that you may not have been aware of.

If you are interested in shell programming (writing shell scripts and functions that automate everyday tasks or serve as system utilities), you should also find this book useful. However, we have deliberately avoided drawing a strong distinction between interactive shell use (entering commands during a login session) and shell programming. We see shell programming as a natural, inevitable outgrowth of increasing experience as a user.

Accordingly, each chapter depends on those previous to it, and although the first three chapters are oriented toward interactive use only, subsequent chapters describe interactive, user-oriented features in addition to programming concepts.

This book aims to show you that writing useful shell programs doesn't require a computing degree. Even if you are completely new to computing, there is no reason why you shouldn't be able to harness the power of bash within a short time.

Toward that end, we decided not to spend too much time on features of exclusive interest to low-level systems programmers. Concepts like file descriptors and special file types might only confuse the casual user, and anyway, we figure those of you who understand such things are smart enough to extrapolate the necessary information from our cursory discussions.

 < Day Day Up > 
 < Day Day Up > 

Code Examples

This book is full of examples of shell commands and programs designed to be useful in your everyday life as a user , not just to illustrate the feature being explained. In Chapter 4 and onwards, we include various programming problems, which we call tasks , that illustrate particular shell programming concepts. Some tasks have solutions that are refined in subsequent chapters. The later chapters also include programming exercises, many of which build on the tasks in the chapter.

Feel free to use any code you see in this book and to pass it along to friends and colleagues. We especially encourage you to modify and enhance it yourself.

If you want to try examples but you don't use bash as your login shell, you must put the following line at the top of each shell script:

#!/bin/bash

If bash isn't installed as the file /bin/bash , substitute its pathname in the above.

 < Day Day Up > 
 < Day Day Up > 

Chapter Summary

If you want to investigate specific topics rather than read the entire book through, here is a chapter-by-chapter summary:

Chapter 1 introduces bash and tells you how to install it as your login shell. Then it surveys the basics of interactive shell use, including overviews of the UNIX file and directory scheme, standard I/O, and background jobs.

Chapter 2 discusses the shell's command history mechanism (including the emacs - and vi -editing modes), history substitution and the fc history command, and key bindings with readline and bind .

Chapter 3 covers ways to customize your shell environment without programming by using the startup and environment files. Aliases, options, and shell variables are the customization techniques discussed.

Chapter 4 is an introduction to shell programming. It explains the basics of shell scripts and functions, and discusses several important "nuts-and-bolts" programming features: string manipulation operators, brace expansion, command-line arguments (positional parameters), and command substitution.

Chapter 5 continues the discussion of shell programming by describing command exit status, conditional expressions, and the shell's flow-control structures: if , for , case , select , while , and until .

Chapter 6 goes into depth about positional parameters and command-line option processing, then discusses special types and properties of variables, integer arithmetic, and arrays.

Chapter 7 gives a detailed description of bash I/O. This chapter covers all of the shell's I/O redirectors, as well as the line-at-a-time I/O commands read and echo . It also discusses the shell's command-line processing mechanism and the eval command.

Chapter 8 covers process- related issues in detail. It starts with a discussion of job control, then gets into various low-level information about processes, including process IDs, signals, and traps. The chapter then moves to a higher level of abstraction to discuss coroutines and subshells.

Chapter 9 discusses various debugging techniques, like trace and verbose modes, and the "fake" signal traps. It then presents in detail a useful shell tool, written using the shell itself: a bash debugger.

Chapter 10 gives information for system administrators, including techniques for implementing system-wide shell customization and features related to system security.

Chapter 11 discusses ways to make bash scripts more maintainable .

Chapter 12 shows you how to go about getting bash and how to install it on your system. It also outlines what to do in the event of problems along the way.

Appendix A compares bash to several similar shells , including the standard Bourne shell, the POSIX shell standard, the Korn shell ( ksh ), the public-domain Korn shell ( pdksh ), and the Z Shell ( zsh ).

Appendix B contains lists of shell invocation options, built-in commands, built-in variables, conditional test operators, options, I/O redirection, and emacs- and vi -editing mode commands.

Appendix C gives information on writing and compiling your own loadable built-ins .

Appendix D looks at the basics of programmable completion.

 < Day Day Up >