Up to main menu         Back to Manual Pages         Next: Background Processes

Korn Shell, C Shell, Bourne Shell, etc.

To give you a bit more flexibility in giving commands to the Unix kernel -- the basic operating system program vmunix -- the commands you type are filtered through a user-friendly (more or less) Unix ``shell''. It allows you to type commands more easily; use wildcards, refer to previous commands, do some Unix programming (shell scripts), and in general get you more results and information for fewer keystrokes. The most widely used shells are

The most basic Unix shell is sh, which has a good set of programming constructs (if/then, loops, redirection of output) and is still the best for writing shell scripts. But for the user typing commands at the prompt, it is much more convenient to use one of the later shells; csh, tcsh, bash, or ksh. The latter, ksh (Korn shell), is popular and is given as the default shell to new users; you can change your default shell (presumably to tcsh) by using the command chsh.

If interested, see the table of differences between the various common shells. Each shell has (long) manual page describing its features.

Major features of a shell

Aliases

An ``alias'' is usually a short succinct word of just a few letters, defined by the user, to take the place of a long Unix command. A couple of common aliases might be
             alias dir='/bin/ls -alF | more'
             alias EE='enscript -2Gr'
These aliases for the Korn shell would be typed into the file ``.profile'' or perhaps ``.kshrc''. For Csh or Tcsh the same aliases would be defined this way;
             alias dir '/bin/ls -alF | more'
             alias EE  'enscript -2Gr'
in the file ``.cshrc''.

Command history

To see a list of your most recent commands, type history. Another common alias, alias h='history', reduces that command to h. The command gives you a list of numbered commands. Then it is easy to repeat a command; in the Korn shell,
             r 89
             r xed
The first command is the Korn shell shorthand for ``repeat command #89''. The second means ``repeat the most recent command which starts with xed. In the two shells csh and tcsh these two ``repeat'' commands would take a different form;
             !89
             !xed

Command line editing

In tcsh one can use the arrow keys to move the cursor backwards or forwards in the current commmand, to insert or delete characters. This is useful if you have made an error at the beginning of a long command, and wish to correct it without erasing everything that follows. Ksh allows this kind of command-line editing also, if the environmental variable VISUAL is set to emacs. If environmental variable VISUAL is set to vi then command-line editing can be done with vi keystrokes, including Esc to enter command mode.

"Sensible" Input/Output redirection

In ksh, as in sh, it's easy to send standard output and standard error into separate files;
      command  > stdout.txt  2> stderr.txt  &
  or
      command  > both.txt  2>&1  &
where the first command sends stdout to file stdout.txt and stderr to file stderr.txt, while the second command sends stdout and stderr together to file both.txt.

The csh and tcsh shells don't provide a sensible way to do this.

Filename completion

In tcsh you get ``filename completion'', which can be very handy. When you are typing a typical command of the form command filename, you can type the first few letters of the filename and then the Tab key, and the name of the file/directory will be completed for you (appending a slash, `/', if a directory). If there are multiple file/directory names which begin with those letters, tcsh completes only as many unambiguous characters as it can; you can type further characters yourself, or type Control-D to see what the choices are.

This seems to be the one area where tcsh beats all the others.

Job control

While you can run multiple background jobs in the basic Bourne shell sh, the more recent shells can list the jobs for you (the command jobs) and let you bring a specific job to the foreground (the command fg).

Directory stack

Any shell beyond sh gives you a way to save a directory stack so that you can easily return to a previous directory. In csh and tcsh you can use the commands
Up to main menu         Back to Manual Pages         Next: Background Processes
Bruce.Fast@Colorado.EDU