9.0 The T Shell


The T Shell or tcsh is an enhanced version of the Berkeley C-shell or csh.

9.1 Shell Variables

The shell maintains a list of variables. Shell variables are of the form name=value . You can invoke the variable by preceding it with a $ sign. The echo command can be used to display the shell values. One special shell variable allows you to customize the command prompt.
% echo $prompt
%
% set prompt="%n@%m%~>"
scot@iriquois~>echo $prompt
%n@%m%~>
scot@iriquois~>
This gives me my username(%n), the @ symbol(@), the machine I am working on(%m), and my current location in the directory structure(the ~ signifies my home directory).

Another type of special shell variable are the environment variables. Enviroment keep track of information that other programs will need. For example, the DISPLAY enviroment variable is used by X windows applications to determine the display location. With X windows you have the option of starting an application on a host and having it display on another machine. Once a variable has been set you can invoke it by preceding its name with a $ sign(for example, $DISPLAY). To get a list of all the current enviroment variables used by your shell use the env command. If you want to change the enviroment variable use the setenv command.

% echo $DISPLAY
creek:0.0
% setenv DISPLAY crow:0
% echo DISPLAY
crow:0
%
Now our X applications will display on crow.

Table9.1: Some T-shell Enviroment Variables
--------------------------------------------------------------
$HOME		Absolute path to your home directory location
$PATH		Where the shell looks for binary files.
$USER		Your login name
$MAIL		Where you mail box is located
$DISPLAY	Where to display X windows applications
$HOST		Current host your are working on
--------------------------------------------------------------
One special enviroment variable is the PATH variable. The PATH is where the shell looks for executable commands. To determine where a command is located in your path use the which command.
% which tcsh
/bin/tcsh
%

9.2 Hashing Tables

The T-shell looks for applications that are located in the $PATH enviroment variable. When you first start a shell it looks through each directory in your $PATH and builds a hasing table of binary files. This is to speed up performance. If you add a binary file to one of the directories in your $PATH and then try to invoke it, it will not be found. You will need to invoke the rehash command to rebuild the hashing table.
% rehash
%

9.3 Aliases

The T-shell support aliases. Aliases are substitute names for commands. The alias command by itself on the command line without any options will give you a listing of the current aliases you are using.
% alias nv rlogin navaho
% nv
login:
We have shorted the command rlogin navho to nv. Aliases can save you a tremendous amount of typing.

9.3 Command History

The T-shell has the ability to remember your previous commands. The history command will give you a complete list of your previous commands.
% history
    1  11:31   ls
    2  11:32   grep.pl array.pl
    3  12:44   rlogin creek -l tai
    4  9:40    ls
    5  9:40    emacs 
%
The number of commands that is displayed is set in your shell startup file. For example, if you put set history=25 savehist=20 in your $HOME/.tcshrc file you can view the last 25 commands and when you exit the shell the last 20 will be saved. To execute one of the commands from the history list use the exclamation point followed by the number of the command.
% !4
ls
spline.m  taylor.m
%
Another way to traverse through commands is by using the and key sequences. The key sequence will give you the previous command and the CTRL-n key will give you the next command in the history list.

9.4 Command Line Editing

One of it major enhancements of the T-shell over the C-shell is command line editing. A number of key bindings are used for this purpose. These key bindings can also be found in the emacs editor, so if you learn these key-binding here you can also use them in emacs. Here is a listing of a few of my favorite key bindings. Try them out. To get a complete listing of all key bindings read the man pages.

Table9.4: T-shell Command Line Editing 
--------------------------------------------------------------
MOVING ON THE COMMAND LINE:
--------------------------
<CTRL-f>  moves the cursor forward one character
<CTRL-b>  moves the cursor back one character
<CTRL-a>  moves the cursor to the beginning of the line
<CTRL-e>  moves to the end of the line

DELETING CHARACTERS
-------------------
BACKSPACE delete the previous character 
<CTRL-d>  delete the current character
<CTRL-k>  delete from the current position to the end of line
<CTRL-u>  delete the whole line

MISC COMMANDS
-------------
<CTRL-p>  list the previous command
<CTRL-n>  list the next command
<CTRL-d>  completes the program name (for example, em<CTRL-D> ,
          will list all the files in your path that start with em)
<CTRL-i>  completes the filename (for example, ls tay<CTRL-i> , 
          will try to complete all files that start with tay)
<TAB>     same as <CTRL-i>
<META-s>  correct the spelling of the previous word. 
          NOTE: The META key is usually set to be the ESC key. 
          (for example, cd /usr/spol/news<META-s> , will correct the 
          spelling of the directory to /usr/spool/news

--------------------------------------------------------------
Try out some of these key sequences.

9.5 Shell Startup Files

When you start a shell it tries to read from a number of files to get information about enviroment variables, paths and aliases. On our system we are using system default files for the tcsh that are located in /etc/csh.cshrc and /etc/csh.login. If you decide to create a $HOME/.tcshrc make sure you keep the path variable.
# Source common aliases & stuff:

   set history=25 savehist=20
   alias h      history
   alias nep    rlogin neptune.tcad.ee.ufl.edu
   set prompt="%n@%m%~>"


set path=($path ~/bin)

You can see I have added my home binary directory to the the system-wide $path variable. Now I can execute commands from my home bin directory

When you make changes to your $HOME/.tcshrc file you use the source command to have the tcsh reread the file. The format is source $HOME/.tcshrc. When you start the tcsh it will try to source /etc/csh.cshrc and then /etc/csh.login if the shell is a login shell. Then it will try to source $HOME/.tcshrc and then $HOME/.cshrc if $HOME/.tcshrc is not found. Then it will source $HOME/.login if the shell is a login shell. On exit tcsh will source first /etc/csh.logout and then $HOME/.logout if the shell was a login shell.



Last Modified: 4/4/94 by Scott Miller