Section 4.1. Introduction to the Shell

4.1. Introduction to the Shell

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.

There are three main uses for the shell:



Interactive use

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.



Customization of your Unix session

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.



Programming

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.



MAC OS X Tiger in a Nutshell
Mac OS X Tiger in a Nutshell: A Desktop Quick Reference (In a Nutshell (OReilly))
ISBN: 0596009437
EAN: 2147483647
Year: 2003
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net