From the KnowledgeBase
Unix: An introduction to Unix shells
Solution:
What is a shell?
A Unix shell is what gives Unix its powerful capabilities. The shell is the
part of the system with which the user interacts, and as such it is arguably
the most important part of a Unix system. A Unix shell interprets commands
such as "pwd", "cd" or "traceroute" and sends the proper instructions to
the actual operating system itself. Other functions of a shell include scripting
capability, path memory, multitasking, and file handling.
Effective February 2, 2004 new Unix accounts (Undergraduate accounts excepted) will be set up with a default Unix shell of /bin/nologin that prohibits login access. If you wish to use a your Unix account, simply change this option by using the Enable Unix Account page. (Log in using your netID and LDAP password.) See How do I enable / change my default Unix shell for more information regarding your options.
Available Shells
There are several shells available on the OIT Unix systems: bash (Bourne Again),
csh (C), ksh (Korn), rksh (restricted Korn), sh, tcsh (Turbo C) and zsh (Z).
(Note that they all include the two letter sequence "sh"). By default, all enabled accounts are set up to use csh (C shell). For those who intend to use Unix more extensively, tcsh (Turbo C Shell) is a popular shell. Bash (Bourne Again Shell) is another popular shell, often used by beginning Computer Science students.
The C Shells
There are two C shells: Csh and Tcsh. Csh is the most common shell on the
Princeton campus because it is the Princeton-specified default. Many commercial Unix systems set ksh as the default; Linux specifies bash. See the Help Desk solution:
How to enable / change your Unix
shell.
There are several nifty things about the C shells:
- Aliasing
- Prompt Customization
- History Recording
- Filename Completion (tcsh only)
The setenv command controls shell variables. For example, if you wanted to
use the M/X Server to use Xterms and other sundry Unix windows in your dorm
room, you could SSH to arizona as usual, and upon entering the shell type
"setenv DISPLAY=yourNetID.student.princeton.edu:0.0". This sets the environment
variable to display all window commands to your PC at home.
Another useful function of setenv variables is use in scripting. In a shell
script, referring to
- $HOME
would be the same as replacing
- $HOME
with
- /u/yourNetID
These variables work the same way in almost all shells.
The Tcsh is an extension of csh, and allows command line editing, file name completion, plus previous command recall via the up-arrow (which are all very useful). Tcsh is very versatile, and has all the features that csh has. Instructions on how to change your shell are
in the Help Desk Online KnowledgeBase. Tcsh offers conveniences.
For example, filename completion is an essential feature of tcsh. When typing
a command, such as netscape, you can type
- netsc
and press [TAB] at this point. Since there are no other commands on the arizona
systems that begin with "mythes", the shell finishes the command for you to
- mythesis_for_school
If you spend much time manipulating files in Unix, you will find this feature indispensable. It works with directory names, as well. In almost any situation, you can fill in filenames and commands using the [TAB] key.
The Bourne Again Shell
The Bash shell is a redundant acronym short for "Bourne Again Shell".
Bash is distributed by almost every archive of free software on the web,
but the original authors were part of the Free Software Foundation, found
at www.gnu.org. Now there exist ports of
bash to several different flavors of Unix.
What advantages are there to using bash? One is that it is made
by the Free Software Foundation. A feature of bash is its way of manipulating
environment variables. For example, bash uses the "export" command to keep
track of the $DISPLAY value (important for using X-terminals) instead of
the csh/sh/tcsh-standard "setenv DISPLAY=" command.
So, if you were logged in via an ssh window and wanted to get windows on
your x server from that session, you would type
export DISPLAY=$REMOTEHOST:0.0
That would set the DISPLAY variable to your logged in host.
When it really comes down to it, these shells are pretty much the same, except
that bash uses somewhat different terminology.
One cool thing about bash is that system crackers do NOT like it. Bash keeps
a record of what commands you execute, and stores it in a file called
.bash_history in your home directory. Since this leaves traces of what commands
are executed by a user of the account, a cracker would either delete this
file or could be detected by looking at backed up copies of the file. Either
way, crackers dislike bash. If you use bash, you can keep tabs on what goes
on in your account.
Some technical notes about bash:
Bash, unlike its ancestor, sh, is completely POSIX-standards conformant.
Sh was written before POSIX standards were in place. Bash also has the capability
of using one-dimensional arrays, a history (unlike sh), argument negation
using the ! character (a la C), and compound brackets and parentheses. Bash
can also be used as a restricted shell, limited to several commands. One
final noteworthy feature of bash is its customizability. Anyone can edit
their .bash* files to suit their preferences. These files include .bashrc,
.bash_profile, and .profile.
The Korn Shell
Unlike Bash, the Korn shell (ksh) and the Korn Restricted Shell (rksh) were
written by David Korn of Bell Labs. What advantages are there to using Korn?
Korn has a command history feature, a command alias
feature, support for shell scripts, arithmetic expressions, filename completion
(disabled by default), and command line editing (also disabled by default).
The sheer number of things disabled by default makes it a chore to start
using any Korn shell. To make matters worse, the K shells all use the "export"
feature, instead of "setenv." (See Bash shell description for details.)
- ksh keeps a 128-command history file by default
- when editing a command at the prompt, you have to use ridiculously annoying keys, starting with ESC, then "h" for right and "l" for left. Arrow keys are not supported.
- You can't change the look of your command prompt.
- Korn shells don't support filename completion.
For more information regarding Unix shells, read the following links:
http://www.faqs.org/faqs/unix-faq/shell/shell-differences
(Internet FAQ Archive, July 1997)
http://www.computerbits.com/archive/1997/1100/lnx9711.html
(Computer Bits, November 1997)

