Technology Tips: Csh, Tcsh

Marvin Crippen, Adaptive Technology Assistant

What is a shell?

A shell is a command language interpreter. It translates your commands so that Unix can understand them. There are a variety of shells and some have more bells and whistles than others. The 3 most common shells are sh (the original, also known as the Bourne shell), csh (Command SHell) and tcsh (an enhanced version of csh). Other shells include bash (Bourne-Again SHell), ksh (Korn SHell) and zsh. The default shell (what you use unless you select something different) on DO-IT's Hawking computer is csh.

csh

Csh features include, but are not limited to, a history mechanism and job control facilities.

History Mechanism

Try typing history at your host system (e.g., hawking) prompt. Csh typically prints out a numbered list of the last 20-30 commands you've typed. To run any of the commands again type !NN where NN is the history number of the previous command. You can also type ! and the first few letters of the command. If you type !ls csh runs the last command that started with ls. If you wish to save more than 20-30 commands in the history list type set history=X where X is the number of items on the history list. Don't make the number too high or csh will run out of memory. To make this change permanent put the set history=X line in your .cshrc (the name of this file is .cshrc no matter what shell you're using) file. It is also possible to do history substitution, running a command from the history list with a few changes to it. For more details on this see the History Substitutions section of the csh manual page (man csh ).

Job Control Features

Let's say you're sending e-mail to someone telling them about the ls command and you want to include a portion of the man page, such as what the -l switch does. You could

  1. postpone the message,
  2. quit Pine (or other electronic mail software you're using),
  3. look up the manual page,
  4. cut out the relevant parts,
  5. quit the man page,
  6. start Pine again,
  7. restart the postponed message and
  8. paste the relevant text.

You would have to go through this process each time you want to copy something from the man page. Or using the job control features of csh you could:

  1. suspend Pine (assuming the enable-suspend feature of Pine is on) by typing <CTRL>-z
  2. look up the manual page
  3. cut out the relevant parts
  4. suspend the man page by typing <CTRL>-Z
  5. go back to composing the message by typing %-
  6. paste the relevant text

If you wanted to copy another section of the ls man page you would type <CTRL>-Z, %- to get to the man page and <CTRL>-Z , %- to get back to Pine.

Typing jobs at your host system prompt displays a numbered list of all suspended jobs. The current job is marked with a plus sign (+) and the previous job is marked with a minus sign (-). To enter a suspended job you can type %+ for the current job, %- for the previous job and %X where X is the number of the job from the jobs command.

tcsh

Tcsh is an enhanced version of the csh. It behaves exactly like csh but includes some additional utilities such as command line editing and filename/command completion. Tcsh is a great shell for those who are slow typists and/or have trouble remembering Unix commands.

Command Line Editing

Command line editing allows you to access any command from the history list and make edits to it before execution. You can use the up and down arrows keys, or <CTRL>-N (Next) and <CTRL>-P (Previous) to cycle through the history list. You can use the right and left arrow keys, or <CTRL>-B (Backward) and <CTRL>-F (Forward) to position the cursor within a command. Typing inserts text into the command, the Backspace and Delete keys can be used to erase characters from the command. Other useful keys are <CTRL>-A to move to the beginning of a line, <CTRL>-E to move to the end of line, and <CTRL>-C to cancel an edit.

File Name and Command Completion

You can use the <TAB>; key to cut down on the amount of typing you do. When you press the <TAB> key tcsh will try to complete either a filename or a command. If the filename is unique tcsh will type the rest of it. If the filename isn't unique tcsh will complete as much as possible and beep. For example, let's say you have a directory called example/testing/ and in that directory you have a couple of text files called file1.txt and file2.txt and a command called reallysuperlongcommand. If you want to run the command in that directory you type ex <TAB> tes <TAB> real <TAB> and tcsh fills in example/testing/reallysuperlongcommand. If you want to look at file2.txt you type more ex <TAB> tes <TAB> fi <TAB> and tcsh writes more example/testing/file. Since file2.txt is not a unique file name tcsh beeps at this point and finishes the line with 2.txt once you press 2<TAB> .

How to change your shell

To change what shell you use type chsh(CHange SHell) and type in the location of the new shell when prompted. The location of tcsh on the Hawking computer is /usr/local/bin/tcsh. The new shell will not take effect until the next time you log on and will stay in effect until you change it again.

For more information about csh and tcsh, consult the appropriate man page (man [shell name]) or send me e-mail at mcrip@u.washington.edu.