The shell is a program that acts as a buffer between you and the operating system. In its role as a command interpreter , it should (for the most part) act invisibly. It can also be used for simple programming. The shell receives the commands you enter using the Terminal (or a similar program), and decides what to do with it.
This chapter provides a basic overview of the shells included with Mac OS X. Refer to Chapter 5 for specific information about Mac OS X's default user shell, bash.
Earlier versions of Mac OS X used the tcsh shell as the default user shell. However, all that changed with Panther (Mac OS X v 10.3), when Apple switched the default user shell to bash. While many people speculated about the change, the main reason Apple switched to bash is for its Unicode support.
The shell is the user interface to Unix, and by the same token, several shells are available in Unix. Mac OS X provides you with more than one shell to choose from. Each shell has different features, but all of them affect how commands are interpreted and provide tools to create your Unix environment.
Let's suppose that the Unix operating system is a car. When you drive, you issue a variety of "commands": you turn the steering wheel, press the accelerator, or step on the brake. But how does the car translate your commands into the action you want? The car's drive mechanism, which can be thought of as the car's user interface, is responsible. Cars can be equipped with front-wheel drive, rear-wheel drive, four-wheel drive, and sometimes combinations of these.
The shell is simply a program that allows the system to understand your commands. (That's why the shell is often called a command interpreter.) For many users, the shell works invisibly behind the scenes and is something they'll never see. Your only concern is that the system does what you tell it to; you don't care about the inner workings. In the car analogy, this is comparable to pressing the brake. Most of us don't care whether the user interface involves disc, drum, or antilock brakes, as long as the car stops when you step on the brake pedal.
When the shell is used interactively, it waits for you to issue commands, processes them (to interpret special characters such as wildcards), and executes them. Shells also provide a set of commands, known as built-ins, to supplement Unix commands.
A Unix shell defines variables, such as the location of your Home directory, to control the behavior of your Unix session. Some variables are preset by the system; you can define others in startup files that are read when you log in or interactively for a single session. Startup files can also contain Unix commands or special shell commands that are executed every time you log in.
A series of individual commands, whether shell commands or other Unix commands available on the system, combined into one executable file is called a shell script. Scripts are useful for executing a series of individual commands, but they can also execute commands repeatedly (in a loop) or conditionally (
if-else), as in many high-level programming languages.
bash, which is Mac OS X Tiger's default user shell, is considered a powerful programming shell, while scripting in tcsh (the default user shell for versions of Mac OS X prior to v. 10.3) is rumored to be hazardous to your health.