Table of Contents |
In recent years, the UNIX operating system has seen a huge boost in its popularity, especially with the emergence of Linux. For programmers and users of UNIX, this comes as no surprise: UNIX was designed to provide an environment thats powerful yet easy to use.
One of the main strengths of UNIX is that it comes with a large collection of standard programs. These programs perform a wide variety of tasks from listing your files to reading email. Unlike other operating systems, one of the key features of UNIX is that these programs can be combined to perform complicated tasks and solve your problems.
One of the most powerful standard programs available in UNIX is the shell. The shell is a program that provides you with a consistent and easy-to-use environment for executing programs in UNIX. If you have ever used a UNIX system, you have interacted with the shell.
The main responsibility of the shell is to read the commands you type and then ask the UNIX kernel to perform these commands. In addition to this, the shell provides sophisticated programming constructs that enable you to make decisions, repeatedly execute commands, create functions, and store values in variables.
This book concentrates on the standard UNIX shell called the Bourne shell. When Dennis Ritche and Ken Thompson were developing much of UNIX in the early 1970s, they used a very simple shell. The first real shell, written by Stephen Bourne, appeared in the mid 1970s. The original Bourne shell has changed slightly over the years; some features were added and others were removed, but its syntax and its resulting power have remained the same.
The most attractive feature of the shell is that it enables you to create scripts. Scripts are files that contain a list of commands you want to run. Because every script is contained in a file and every file has a name, scripts enable you to combine existing programs to create completely new programs that solve your problems. This book teaches you how to create, execute, modify, and debug shell scripts quickly and easily. After you get used to writing scripts, you will find yourself solving more and more problems with them.
I assume that you have some familiarity with UNIX and know how to log in, create and edit files, and work with files and directories to a limited extent. If you havent used UNIX in a while or you arent familiar with one of these topics, dont worry. The first part of this book reviews this material thoroughly.
This book is divided into three parts:
Part I consists of Chapters 1 through 6. The following material covered in the individual chapters:
By this point, you should have a good foundation in the UNIX basics. This will enable you to start writing shell scripts that solve real problems using the concepts covered in Part II. Part II is the heart of this book, consisting of Chapters 7 through 18. It teaches you about all the tools available when programming in the shell. The following material is covered in these chapters:
At this point, you will know enough about the shell and the external tools available in UNIX that you can solve most problems. The last part of the book, Part III, is designed to help you solve the most difficult problems encountered in shell programming. Part III spans Chapters 19 through 24 and covers the following material:
Each chapter in this book includes complete syntax descriptions for the various commands along with several examples to illustrate the use of commands. The examples are designed to show you how to apply the commands to solve real problems. At the end of each chapter are a few questions that you can use to check your progress. Some of the questions are short answer while others require you to write scripts.
After Chapter 24, three appendixes are available for your reference:
About the Examples
As you work through the chapters, try typing in the examples to get a better feeling of how the computer responds and how each command works. After you get an example working, try experimenting with the example by changing commands. Dont be afraid to experiment. Experiments (both successes and failures) teach you important things about UNIX and the shell.
Many of the examples and the answers to the questions are available for downloading from the following URL:
http://www.csua.berkeley.edu/∼ranga/downloads/tysp1.tar.Z
After you have downloaded this file, change to the directory where the file was saved and execute the following commands:
$ uncompress tysp1.tar.Z $ tar xvf tysp1.tar
This creates a directory named tysp1 that contains the examples from this book.
There is no warranty of any kind on the examples in this book. I have tried to make the examples as portable as possible, and to this end I have tested each example on the following versions of UNIX:
It is possible that some of the examples might not work on other versions of UNIX. If you encounter a problem or have a suggestion about improvements to the examples or the content of the book, please feel free to contact me at the following email address:
ranga@soda.berkeley.edu
I appreciate any suggestions and feedback you have regarding this book.
Features in this book include the following:
Notes give you comments and asides about the topic at hand, as well as full explanations of certain concepts.
Tips provide great shortcuts and hints on how to program in shell more effectively.
Cautions warn you against making your life miserable and avoiding the pitfalls in programming.
Paragraphs containing new terms feature the New Term icon. The new term appears in italic.
At the end of each chapter, youll find a handy Summary and a Quiz section (with answers found in Appendix C). Many times, youll also find a Terms section.
In addition, youll find various typographic conventions throughout this book:
Table of Contents |