C Shells To Be Sure

Heeding conventional wisdom can be a good thing, although there are drawbacks tofollowing it at times. for instance, when new information is introduced.  Conventional wisdom says that system Administrators should use derivatives of the bourneshell (sh, ksh, bash).  It also suggests that users should use the Cshell (csh).

The reasons for this are historical.  Way back in the dark ages (before the term'information superhighway' was coined), only the C shell had interactiveusage features like history, jobs and aliases.  Currently, which shell you use is amatter of preference, because there are several shells available that have all the usualinteractive features.


For users that have the csh as their login shell, why not try the tcsh,officially named The Enhanced C Shell, instead?

It's available on the network in several places for ftp downloads.  You might try ftp.deshaw.com in /pub/tcsh or ftp.gw.com in /pub/unix/tcsh.  Compiling and installing instructions are included in the tar file.  Mostsites install tcsh in /usr/ local/bin, though I haveseveral customers with it in /usr/bin or /bin.

If you, as a system administrator, want to allow users to have the tcshfor a login shell, its complete pathname must be listed in /etc/shells.  If your system does not have that file and you create it, be sure to list allshells that are valid as login  shells, not just the pathname to tcsh.

Once installed and edited into /etc/shells, a user can use the chshcommand to make the tcsh their default login shell.  Be sure toinclude the complete pathname to tcsh when running chsh.  This can be found with the command which tcsh.

The funny part about having a system administrator go through all that work, is thatmany people are not aware of the tcsh even if it is installed.  Forexample, at one of the sites where we do a lot of training, they have over 4,000 entriesin the NIS password map.  Of those, over 3,500 use the csh.  Only 285 were using the tcsh (most of the remaining were using ksh).

Since tcsh is a complete superset of the functionality of the csh,there's no training period required.  You can use the tcsh exactlylike the csh, in fact, it will even read the same .cshrcstartup file.  Then you can start learning about the new features when you have time.


First the disadvantages.  Actually, I can only think of one, and we alreadymentioned it.  The tcsh is not shipped with most systems, HP-UXincluded.  This means that you cannot use tcsh unless someoneproperly installs it on your system.

In addition, there are some annoying quirks about the tcsh command andfile spelling correction mechanism.  Luckily, you can turn it off (or customize it).  More on that later.

As for the pros, the tcsh man page lists the enhancements from the csh.  There are many, but the best are:

  • Command line editing
  • Visual history recall
  • Automatic terminal setting sanity check
  • Improved command completion
  • More powerful prompt assignments
  • More variables
  • Enhanced wildcards

To see if tcsh is installed, issue the command which tcshfrom a csh.  If it returns a pathname, tcsh isavailable.  You can enter exec tcsh to change your current cshto a tcsh.  Better yet, change your login shell to tcshwith the chsh command (on HP-UX) as mentioned above.  To see if itworked, logout and back in, then issue echo $tcsh.

If it returns a version number, you're in the tcsh.  If you getand "Undefined Variable" error, you're still in a csh (orsomehow ended up with a korn shell).  If the chshdidn't work, ask a system administrator for help (or e-mail me).


Now that you have a tcsh running, let's explore a little bit.  The first two features in the list above are enabled together with bindkeycommand.  The -e option enables emacs-style commandline editing.  The -v options enables vi-style.  Choose the editor you're most comfortable with.  Details of the editors can befound in the tcsh man page.  Both command line editor styles allowyou to do more than backspace over a command (which is all the cshallows).  This is called "Command Line Editing."

If you're entering a command and realize you made an error in the pathname severalcharacters back, you can use standard editor commands to move the cursor back and fix twithout losing the rest of what you typed.  In vi mode, hit <esc>to get to vi commands, then issue editor commands:  In emacsmode, use the usual emacs control sequences.

As long as you have either emacs- or vi- stylecommand line editing enabled , you also have the visual history capability enabled.  After issuing several commands, you can use the up arrow key to recall previousones.  They are merely printed on the command line, so you can also perform edits onthem before pressing <return> to issue (or <ctrl-c> toabort) the command.  If the arrow key does not work, or if you prefer, you can alsouse <ctrl-p> to recall previous commands (<esc-k> in vimode).


The bindkey command can also be used to map editor commands, commandsor strings to a key.  This can really save time if you use long commands or stringsoften.

The csh has command and username completion, which all you cshuser should be familiar with, and using.  In the csh, if the filecvariable is set, you can type part of a filename, the hit <esc> and theshell will fill in the rest (if what you typed was unique).  If what you typed wasambiguous, a <ctrl-d> will provide a list of possible completions so youcan type enough to allow the shell to complete the name for you.

The tcsh does the same thing, with the exception that it uses the <tab>key instead of the <esc> key to invoke the completion.  It also cancomplete variables.  For example, if you type in echo $tc<tab>,it will complete the rest of the variable named tcsh.

The tcsh also allows you to program completions to work in a specificmanner.  This is done with the built in command called complete.

Want more?  Next column we'll look at some more features of the tcsh.