The Shell

What is the Shell?

In Windows and the MacOS, you access files and programs by clicking on icons and menus. The computer shows you pretty pictures, and you respond by pushing buttons and moving the mouse.

Every operating system has a interface - the point of contact between the human and the machine. This interface is called a GUI (Graphical User Interface) on Windows and MacOS. In UNIX, the interface is called the shell.

User-Shell-Kernel interaction

Notice that there is more than one user using the UNIX machine. Each user gets their own copy of a shell.

The shell is your interface to UNIX. It is the component of UNIX that acts as an intermediary on your behalf. If you and your shell get along, your UNIX experience will be a good one.

Specifically, the shell handles the following for you:

  • Finds and executes programs
  • Provides you with access to your files
  • Makes it easy (or hard) to recall earlier commands and edit command lines

Types of Shells

Since UNIX culture is so diverse, there are many shells to choose from. They differ mainly in terms of how much pain the user likes, and which lineage they come from.

UNIX name English name Decendant of Pain level Features
sh Bourne Shell (First shell) Extremely high Easy to script, great to use if you are made of silicon
csh C Shell (Second shell) High Command aliasing, job control
tcsh TC Shell csh Tolerable Filename completion, history, aliasing
ksh Korn Shell sh Low Filename completion, command line editing
bash Bourne Again Shell sh Pain-free, a real pleasure to use Cursor keys, filename completion, reliable backspace

Pain refers to the amount of frustration you will experience as a new user. This frustration stems mostly from having "broken keys" - keys that do not function as expected, such as the cursor keys and backspace.

Shell choice is a very personal matter. While I recommend bash to new users, you may find that you like a different shell.

Environment Variables

You are probably curious about what shell you are using. In fact, you may be wondering where information like this is stored - information about your environment.

Your shell has a number of things called environment variables. These are variables (ie, a placeholder for information) that many programs look for in order to know how to behave. Let's look at an example.

Type the following into your UNIX session:

steel /N/fs1/clwolfe/Steel $ echo $SHELL

You should see something like this:

/usr/local/bin/bash

We just used the echo command to access the value of the $SHELL environment variable. The vaule turned out to be /usr/local/bin/bash. This means that I am using the bash shell.

There are many other environment variables. To get a full listing, try this:

steel /N/fs1/clwolfe/Steel $ printenv

TZ=US/East-Indiana

HOSTNAME=steel.ucs.indiana.edu

MANPATH=/usr/share/man:/usr/local/man:/usr/local/gnu/man:/opt/SUNWspro/man:/usr/X/man

PS1=\h \w $ 

USER=clwolfe

MACHTYPE=sparc-sun-solaris2.6

MAIL=/var/mail/clwolfe

LINES=23

EDITOR=pico

LOGNAME=clwolfe

SHLVL=1

COLUMNS=80

SHELLOPTS=braceexpand:hashall:histexpand:monitor:interactive-comments:emacs

SHELL=/usr/local/bin/bash

PRINTER=none

HOSTTYPE=sparc

OSTYPE=solaris2.6

HOME=/N/u/clwolfe/Steel

TERM=vt100

PATH=/N/u/clwolfe/Steel/bin:/usr/sbin:/usr/local/bin:/usr/local/gnu/bin:/bin:/usr
	      /bin:/usr/ucb:/opt/SUNWspro/bin:.:/usr/X/bin

SSH_TTY=/dev/pts/22

EXINIT=set redraw wm=10

Most of this information isn't very useful right now, but we'll need it later. Now, let's try setting a new variable of our own creation. Suppose we would like the variable $MYVAR to have the value "ImportantStuff".

The first thing to do is to find out what shell you are using, because (sigh) the syntax is different for the various shells. Then follow the instructions below.

sh MYVAR="ImportantStuff"; export MYVAR
bash, ksh export MYVAR="ImportantStuff"
csh, tcsh setenv MYVAR "ImportantStuff"

Now let's try accessing the variable.

steel /N/fs1/clwolfe/Steel $ echo $MYVAR
ImportantStuff

Notice that we didn't use the dollar sign when setting a variable, but we did when accessing the variable. MYVAR will exist until you logout, at which point it disappears.


Next: Commands
Prev: Connecting to a UNIX Machine
Up: Table of Contents