[Next] [Previous] [Up] [Top] [Contents] [Index]

Chapter 4: Shells

4.1 Introduction to Shells

The kernel is the real operating system and is loaded into memory at boot time. Typically the user never interacts directly with the kernel. The utilities are programs stored on disk, and loaded into memory by the kernel when invoked.

A shell is a utility. It is run in user mode, and does not have system privileges. You have a default shell, and you can invoke other shells. Invoking shells is discussed in section 4.1.2.

The shell is the interface between the operating system and the user. It interprets the commands you type and the keys you press in order to direct the operating system to take an action. Shell scripts, which are analogous to DCL command files, allow you to use the shell as an interpretive programming language. They are introduced in section 4.4, but a comprehensive treatment of scripts is beyond the scope of this manual.

There are two families of shells: one based on the Bourne shell (this family also includes the Korn (ksh) and Bourne-again (bash) shells), and the other based on the Berkeley/C shell. The shells themselves will be discussed and compared in section 4.2.

4.1.1 Determining Your Current Shell

There are several commands available in all the shells that furnish this information. We present four examples below with sample output for csh. The first three, echo, env and finger, will show only your login shell. If you have invoked another shell, these commands will not reflect the new shell. ps lists information about all your active processes.

% echo $SHELL

displays the value of the variable name that follows the $; example output: /bin/csh

% env or printenv

shows all defined environment variables, including SHELL; example output: SHELL=/bin/csh

% finger your_username

shows user information and login shell; example output:

        Login name: username                       In real life: {your name}
        Directory: /afs/fnal.gov/files/home/room3/{username} Shell: /bin/csh

Finally,

% ps

shows processes, including shell; example output:

        PID TTY      TIME COMD
        6264 pts/11   0:03 csh

[Missing image]Note that on some of the more recent OS releases (e.g., AIX+4 and IRIX+6.4, and likely others in the near future) /bin/sh is a link (links are described in section 6.3.5) to the korn shell (ksh). ksh is a superset of sh, so this shouldn't present any problems for you. One difference is that your .shrc file (see section 9.4.2) gets sourced when you run /bin/sh scripts.

4.1.2 Starting a Shell

A shell is started by a login process. A new shell is also started for each invocation of a terminal window or shell script (see section 4.4). Which shell gets invoked is determined by the last field in your entry in the password entry file. In a standard UNIX file system you can display your password entry by the command:

% grep ^username /etc/passwd

(grep is described in section 6.4.2.; the use of ^ is explained in section 5.4.5.) To display your password entry in an NIS environment, use the command:

% ypmatch username passwd

(The NIS command ypmatch is not described in this manual.) Sample ypmatch output from the FNALU system, for which the default shell has been set to csh, looks like:

aheavey:!:6302:1525:Name of User:/afs/fnal.gov/files/home/room3/aheavey:/bin/csh

When you log in, the login process invokes a shell program (e.g., /usr/local/bin/tcsh or /usr/local/bin/bash) and transfers control to it. The shell displays a prompt indicating it is ready for your input. The default UNIX prompts are symbols that indicate which shell is invoked (recall from section 2.3 that your prompt is likely to be set differently):

On FNALU the prompts are set to indicate the host machine, for example <fsui01>, or <fsgi02>. At any point in your session you can invoke another copy of the same shell or a different shell by typing the shell name at the prompt, for example:

% csh

invokes csh (C shell). This new shell, or "subshell", sits on top of your current shell. The execution of the original shell is then suspended (the shell is put to sleep), and the new shell takes control. Upon quitting the new one, the original shell wakes up and resumes control.

The average user at Fermilab does not have the privilege to change the password entry file. Therefore, to change your default shell you will need to ask your system manager.

4.1.3 Exiting a Shell

To exit a shell and return to the calling shell, type exit at the prompt. Repeat the exit command once for each subshell; when you reach your initial shell, your terminal emulation is closed, and the terminal window disappears. Instead of exit you may need to enter <Ctrl-d>.


UNIX at Fermilab - 10 Apr 1998

[Next] [Previous] [Up] [Top] [Contents] [Index]