|< Day Day Up >|
Chapter 15. Shell Configuration and Programming (Shell Scripting)
IN THIS CHAPTER
In the preceding several chapters, we have introduced you to the wide range of possibilities inherent in being able to access the Unix subsystem at the command line. Although we've said that being able to type to the command line can give you the power to do things that you've never been able to do before, we've also repeatedly hinted that there were ways that you could automate much of the typing and build your own mini-programs. In this chapter, we'll cover the final things you need to know to make this a reality.
With Mac OS X 10.3, Apple changed the default user shell from tcsh to bash. 10.4 maintains this default. Because of this, not all of you will be using the same shell. Unfortunately, the mechanical details of these shells are different enough that they can't both be easily covered in a single discussion without becoming confusing. The concept of shell scripting itself, and of automating your command-line tools, is universal, however, and does not depend on what shell you're using to work in. Therefore, this chapter is divided into sections that discuss scripting as a concept and in which we'll use one shell or the other, whichever is most illustrative of the scripting point at hand, to generate our primary examples and subsections that discuss the mechanistic and syntactic details of the bash and tcsh shells themselves, as well as how these relate to the general scripting concepts. When you come to one of these shell-specific sections, concentrate on the version that deals with your shell.
We wish we could put enough pages in this book to provide identical coverage of both. Unfortunately, if our popular reviews are correct, we'd need to put wheels and a tow-handle on the book if we did. To cut down on the bulk and weight a little bit, we'll confine most extended discussions, examples, and listings to one, or the other shell sections (the bash section, whenever it's possible to make the point clearly in bash). Because of this, regardless of which shell you're using, you'll want to skim the other section after reading the specifics of yours to catch any places where the other goes into greater detail. You'll be able to generate the analogous examples for each by following along with what is done in the other shell and applying the details regarding differences that we've provided in the section specific to your shell.
If you're interested in using a different shell, you'll find that the concepts and capabilities we cover here are almost universal, though the syntax and advanced features of these and other shells will differ somewhat. Some shells, such as zsh, have so many additional features beyond what we can cover there that a complete description of their use is sufficient to fill a book or two of their own.
Don't let the idea of multiple differing shell syntaxes sound intimidating to you. Even if you don't realize it yet, for whatever shell you're working in, you already know shell syntax. It's what you've been using for the last six chapters. To make the best use of the command-line environment, you'll also need to know about shell variables, conditional statements, and looping structures. At this point in your command-line experience, these will not be difficult details to master.
|< Day Day Up >|