Previous | Table of Contents | Next |
In the preceding section, I explained that when you type the command
$ date
the computer executes the date command and displays the result.
But how does the computer know that you wanted to run the command date?
The computer uses a special program called the shell to figure this out. The shell provides you with an interface to the UNIX system. It gathers input from you and executes programs based on that input. When a program finishes executing, it displays that programs output.
For this reason, the shell is often referred to as the UNIX systems command interpreter. For users familiar with Windows, the UNIX shell is similar to the DOS shell, COMMAND.COM.
The real power of the UNIX shell lies in the fact that it is much more than a command interpreter. It is also a powerful programming language, complete with conditional statements, loops, and functions.
If you are familiar with these types of statements from other programming languages, great. Youll pick up shell programming quickly. If you havent seen these before, dont fret. By the time you finish this book, youll know how to use each of these statements.
The prompt, $, which was discussed in the beginning of this chapter, is issued by the shell.
While the prompt is displayed, you can type a command. The shell reads your input after you press Enter. It determines the command you want executed by looking at the first word of your input. A word is an unbroken set of characters. Spaces and tabs separate words.
To the shell, your input looks like the following:
$ word1 word2 word3 ... wordN
The shell always picks word1 as the name of the command you want executed. If there is only one word
$ date
the shells job is easy. It executes the command. If there are more words
$ who am i
the shell passes the extra words as arguments to the command specified by word1.
You might notice that your prompt looks slightly different than the $ prompt I am using. The actual prompt that is displayed depends on the type of shell you are using.
In UNIX there are two major types of shells:
If you are using a Bourne-type shell, the default prompt is the $ character. If you are using a C-type shell, the default prompt is the % character. This book covers only Bourne-type shells because the C-type shells are not powerful enough for shell programming.
Note:
In UNIX there are two types of accounts, regular user accounts and the root account. Normal users are given regular user accounts. The root account is an account with special privileges the administrator of a UNIX system (called the sysadmin) uses to perform maintenance and upgrades.If you are using the root account, both the Bourne and C shells display the # character as a prompt. Be extremely careful when executing commands as the root user because your commands effect the whole system.
None of the examples in this book require that you have access to the root account to execute them.
The different Bourne-type shells follow:
The different C-type shells follow:
Unless explicitly noted, the examples and exercise answers in this book will work with any Bourne-type shell.
Previous | Table of Contents | Next |