previoussection   next section   upper level


Section 4: The Unix Shell

The shell is perhaps the most important program on the Unix system, from the end-user's standpoint. The shell is your interface with the Unix system, the middleman between you and the kernel.

CONCEPT: The shell is a type of program called an interpreter. An interpreter operates in a simple loop: It accepts a command, interprets the command, executes the command, and then waits for another command. The shell displays a "prompt," to notify you that it is ready to accept your command.

The shell recognizes a limited set of commands, and you must give commands to the shell in a way that it understands: Each shell command consists of a command name, followed by command options (if any are desired) and command arguments (if any are desired). The command name, options, and arguments, are separated by blank space.

CONCEPT: The shell is a program that the Unix kernel runs for you. A program is referred to as a process while the kernel is running it. The kernel can run the same shell program (or any other program) simultaneously for many users on a Unix system, and each running copy of the program is a separate process.

Many basic shell commands are actually subroutines built in to the shell program. The commands that are not built in to the shell require the kernel to start another process to run them.

CONCEPT: When you execute a non built-in shell command, the shell asks the kernel to create a new subprocess (called a "child" process) to perform the command. The child process exists just long enough to execute the command. The shell waits until the child process finishes before it will accept the next command.

EXERCISE: Explain why the exit (logout) procedure must be built in to the shell.

EXPLANATION: If the logout procedure were not built in to the shell, the kernel would start a new child process to run it. The new process would logout, and then return you to the original shell. You would thus find yourself back where you started, without having logged out.

Unlike DOS, the Unix shell is case-sensitive, meaning that an uppercase letter is not equivalent to the same lower case letter (i.e., "A" is not equal to "a"). Most all Unix commands are lower case.

Entering shell commands

The basic form of a Unix command is: commandname [-options] [arguments]

The command name is the name of the program you want the shell to execute. The command options, usually indicated by a dash, allow you to alter the behavior of the command. The arguments are the names of files, directories, or programs that the command needs to access.

The square brackets ([ and ]) signify optional parts of the command that may be omitted.

EXAMPLE: Type the command

ls -l /tmp

to get a long listing of the contents of the /tmp directory. In this example, "ls" is the command name, "-l" is an option that tells ls to create a long, detailed output, and "/tmp" is an argument naming the directory that ls is to list.

Aborting a shell command

Most Unix systems will allow you to abort the current command by typing Control-C. To issue a Control-C abort, hold the control key down, and press the "c" key.

Special characters in Unix

Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.

The shell meta characters include:

\ / < > ! $ % ^ & * | { } [ ] " ' ` ~ ; 

Different shells may differ in the meta characters recognized.

The meaning of some of the meta characters, and ways to use them, will be introduced as the tutorial progresses.

Getting help on Unix

To access the on-line manuals, use the man command, followed by the name of the command you need help with.

EXAMPLE: Type

man ls

to see the manual page for the "ls" command.

EXAMPLE: To get help on using the manual, type

man man

to the Unix shell.


previoussection   next section   upper level