Introduction to UNIX command shells October 21, 1998
John C Vernaleo
University of Rochester
The UNIX operating system consists of two parts: the kernel and the shell. The Kernel is the part of the operating system that deals with all of the computer functions. The Shell is the part of the operating system which the user interacts with. Technically it is a "command line interpreter", but it can be thought of as the command prompt. The Shell then translates these commands for use by the Kernel. The Shell is also the program which reads and executes the user startup files (.cshrc usually) when a user logs in as well as allowing the user to write and execute scripts.There are several different varieties of Kernels and Shells. The Kernel depends on what Kernel was installed on the system one is working on. It is not user changeable, and not generally an issue. The Shell however is very important.
There are five different common shells as well as several other
less common varieties. To see which shell is currently running, type the command:
echo $shell
at the prompt. Something similar to:
/opt/local/bin/tcsh
will show up on the screen, where the name after the last slash (/) is the shell currently
running.
The possible different common shells are:
sh Bourne shell
csh C shell
tcsh TC shell
ksh Korn shell
bash Bourn Again shell
To see which of these shells is available on a given system, type the command:
cat /etc/shells
This will show a list of available shells, as well as the directories they lie in.
Each of the different Shells offers some different features. The Bourne shell is the oldest of the shells and probably should not be used. The Bourne Again shell is as the name implies an update on the Bourne shell. It is not available on many systems and is therefor not the best choice either. The C shell and the TC shells are both very similar. They both follow a C language type system for running scripts (which are basically programs). TC shell is the newer of the two and offers some advanced options as well as emacs style editing (emacs is one of the more advanced UNIX text editors). TC shell should be used if at all possible since it is both a good shell and the only shell on which the PhATsoftware will run. The Korn shell is very similar to the TC shell, only with a different script programming language. Both TC and Korn offer a command history to avoid retyping commands. This is not available on the older shells.
There are several different ways to switch between the various shells on a system.
1) The first method is to type the name of the
shell you wish to use at the prompt. This does not change the login shell, only the
shell currently in use. It is not possible to logout from a shell that is not the user's
login shell. To logout, type:
exit
at the prompt to return to login shell. Then logout normally. When user logs in again,
original login shell will load. This method should work on all systems.
2) The second method is to change the user's login shell. At the prompt
type:
chsh
This command will display the current login shell and prompt the user to enter a new
shell. The new shell will not take effect until the user has logged out and logged back in
again. Although this is the preferred method, it is not available on all systems.
3) An alternative method is to use the passwd command to change the
login shell. This is done by typing:
passwd -e
at the prompt. This method is not available to normal users. Only those with special
access (system administrators or the root user) may use this option.
There are several environment and shell variables (such as the number of stored
commands in history, the time before automatic logout, etc.) in UNIX. To make these
variables follow the user to another shell, they must be put in the startup file, .cshrc
(or on some systems, .tcshrc). To set variables in this file, open it with a text editor.
Variables (both shell and environmental) may be added or changed as desired. The
general syntax for a variable statement in this file is:
set variable_name=value
for a shell variable, or:
setenv variable_name=value
for environmental variables.
Save the file and close the editor. This file will be run every time a shell
starts. To force the shell to run this (as in if it has been changed since the last start
up) type:
source .cshrc
at the prompt.