Shells
======
In Unix, a shell is the program you get automatically after login. All
shells display a prompt such as "$" and wait for you to enter a command
which they then process, usually by calling the appropriate program.
Such programs are called command line interpreters.
Shell is just a program
~~~~~~~~~~~~~~~~~~~~~~~
Before Unix, interpreting the users' commands was done by a part of the
operating system (OS). One of the best ideas in Unix was taking this
job out of the OS and giving it to an ordinary program - the shell.
This approach has several advantages.
o Users have a choice of shells. System developers can give users
menu-driven shells if needed. The name of the chosen shell is held
at the end of the user's entry in the passwd file.
o You can write your own if you don't like the standard ones.
o Shells can be written in high-level languages by programmers who
don't need to be experts in writing OSs.
o The OS kernel is smaller and simpler.
Best-known shells
~~~~~~~~~~~~~~~~~
The four best-known shells are: the Bourne shell (sh - which we are
learning), the C shell (csh), the Korn shell (ksh) and the Bourne-again
shell (bash). We are learning the Bourne shell because it is the
standard one and is described in every Unix text book. We are using
`bash' because of its command line editing facility.
The most useful features of the C shell are:
o history - which allows you to re-use old commands, either as they
were or slightly modified. I think this isn't so useful when using
xterms as we are.
o alias - which allows you (or CIS!) to execute rm -i instead of rm so
that you have to confirm every file deletion. Any command can be
aliased.
o noclobber - lets you avoid overwriting files when using re-direction
For example: date > precious would not overwrite precious.
Some people like the C-like syntax of the C shell.
The Korn shell keeps the same basic syntax as the Bourne shell but
includes some of the most useful features of the C shell. Some people
think is gets its name because it combines the C and Bourne shells but
this is not so; the Bourne and Korn shells are named after their
authors. The C shell gets its name from its C-like syntax.
Bash is an improved version of the Bourne shell. It also, contains
history and alias commands. Additionally, it has very comprehensive
editing facilities for the command line. If it is invoked under the
name `sh', it tries to bahave as if it were the Bourne shell.
Shell doesn't do it all
~~~~~~~~~~~~~~~~~~~~~~~
Shells have very few built-in commands; mostly they call self-contained
little programs such as `rm', `cp', and `mv' to do even the most basic
tasks. This approach has several advantages.
o It is very easy to add new commands to Unix because all you have to
do is make an executable file available with a suitable name.
o Apart from the built-in commands, the same set of Unix commands is
available from all the different shells.
o Since shells deal with the filename expansion (wild cards), programs
such as `rm', `cp', and `mv' do not have to do it, and their authors
can concentrate on the main task of the program.
o Since shells deal with input-output redirection, the little programs
do not have to do it.
o the small programs do not need to open standard input and output
because they inherit them from the shell.
o The shells are smaller and simpler.
o Less-skilled programmers can write commands.
Shell scripts
~~~~~~~~~~~~~
A shell script is simply Unix commands stored in a file that has been
made executable.
Importance of shell scripts
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shell scripts are important because they:
o are an easy way of adding new commands;
o allow prototyping of new commands or systems;
o allow on-off systems to be developed easily;
o are the means by which Unix and especially Linux services are
configured.
The above are only possible because the standard shells provide a
complete programming language.
Shell scripts are useful because they:
o allow re-use of tricky commands without working them out again;
o automate routine tasks;
o save typing;
o allow the user's environment to be tailored.
Wed Mar 5 13:49:35 GMT 2003