Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: II. Let the Computer Do the Dirty Work Chapter 8Next: 8.2 Introduction to bash

8. How the Shell Interprets What You Type

What the Shell Does
Introduction to bash
Introduction to tcsh
Command Evaluation and Accidentally Overwriting Files
Command-Line Evaluation
Output Command-Line Arguments
Setting Your Search Path
A Directory for Commands You Shouldn't Run
Wildcards Inside of Aliases
eval: When You Need Another Chance
Which One Will bash Use?
Which One Will the C Shell Use?
Is It "2>&1 file" or "> file 2>&1"? Why?
Bourne Shell Quoting
Differences Between Bourne and C Shell Quoting
Quoting Handles Special Characters in Filenames
verbose and echo Variables Show Quoting
Here Documents
"Special" Characters and Operators
How Many Backslashes?

8.1 What the Shell Does

As we've said, the shell is just another program. It's responsible for interpreting the commands you type; there are four or five commonly used shells, and several other variants (1.8) kicking around.

Interpreting your commands might seem simple enough, but a lot of things happen between the time you press RETURN and the time the computer actually does what you want. The process of interpretation is very complex: the shell has to break the command into words, expand aliases (10.2), history operators (11.1), and shell and environment variables (6.8, 6.1). It also sets up standard input and output streams (13.1) and performs a lot of other tasks. Indeed, if a command looks right but doesn't work right, the cause is probably either:

I'd say that file permission problems are more common, but it's a close call. File permission problems are usually easy to understand, once you know what to look for, but the rules by which a shell interprets your command line are another thing altogether. Lest I scare you, we'll try to go slow with this material. Although it's difficult, understanding how the shell parses your commands is important to becoming a power user.

In this chapter, we'll look at how a UNIX shell interprets commands. The standard shells (the C shell, Bourne shell, and Korn shell) have similar interpretation rules. The C shell can be tricky at times, mostly because its behavior isn't as well defined as the others. However, there's nothing "magical" about these rules. Tomorrow morning, you may grab some new shell from the Net (52.9), and find out that it has a new and different way of interpreting commands. For better or worse, that's what UNIX is all about.

As part of this discussion, we'll cover quoting, which is the mechanism by which you can turn off the special meanings that the shell assigns to some characters. Quoting is an integral part of command-line processing; it allows you to control what the shell will do to your commands.

- ML

Previous: II. Let the Computer Do the Dirty Work UNIX Power ToolsNext: 8.2 Introduction to bash
II. Let the Computer Do the Dirty Work Book Index8.2 Introduction to bash

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System