Thomas C-SHELL

The following topics are discussed in this section:

GENERAL INFORMATION

The tc shell (version 6.02.00) is an interactive command interpreter and command programming language. The shell carries out commands specified at the terminal or from a file. The tc shell uses a syntax that is very similar to that of the C programming language. It is based on the Berkeley UNIX C shell plus many added utilities.

GETTING STARTED

The tc shell is executed by the login command if it is your default shell, or by issuing the tcsh command. When executed, the shell runs commands found in the /etc/profile file and then in your $HOME/.cshrc file. You can reload the C shell by issuing the command source ~/.cshrc.

USING THE TC SHELL

The tc shell incorporates all the aspects of the c shell. This document will cover some of the new features found only in the tc shell. For information on the c shell, please see the C-shell handout.

Editing the Command Line

The tc shell allows you to use emacs commands to edit the command line. The use of the bindkey command helps make this possible. With no arguments, this command displays the setting for each of the key combinations. You can also use it to set the meaning of a key sequence. The syntax for the command is:
     bindkey [instring [outstring | command]]
where instring is the key sequence, outstring is the key sequence to be produced, and command is a command to bind to the specified key sequence.

Below is a table showing some of the emacs key bindings and a brief description of each.

Key           Brief Description          Key          Brief Description
-------------------------------------------------------------------------------
[Up Arrow]    Up 1 command in history    [Down Arrow] Down 1 command in history
[Right Arrow] Forward one character      [Left Arrow] Back one character
[CTRL][A]     Go to beginning of line    [CTRL][D]    Delete character
[CTRL][E]     Go to end of line          [CTRL][H]    Delete back one char
[CTRL][I]     Complete the file name     [CTRL][K]    Delete to end of line
[CTRL][L]     Issues a clear command     [CTRL][R]    Redisplay the screen
[CTRL][S]     tty-stop-output            [CTRL][Q]    tty-start-output
[CTRL][U]     Kill the command line      [CTRL][Y]    Yank text
[CTRL][C]     tty-sigintr                [CTRL][Z]    tty-sigtsusp
[CTRL][\]     tty-sigquit                [CTRL][]]    tty-dsusp
By default, the shell is in insert mode. Therefore, any text you type will be inserted into the command line at the current cursor position. You can change the default input mode by setting the input mode environment variable to a value of overwrite.

Word Completion

The tc shell will complete your word for you, provided you give it a unique base from which to start the search. When you press the [TAB] key, the shell will search for a word that begins with the typed text. If it can find a unique match, it will place the rest of the word on the command line. If a unique match can not be found, the shell will complete as much of the word as possible before the ambiguity. The shell will also cause the terminal to beep when the completion (if any) is done. This function is useful for the completion of long filenames. The shell will search the directories specified by the path variable for commands that match the substring and then search the current directory for a file name matching the substring.

An additional function is provided by the [CTRL] [D] key sequence. This will display a columned list of all possible words that match what is typed. If the word is a complete subdirectory name, this function will display all the files in that directory. Note that the [CTRL] [D] sequence must be issued at the end of the command line to work in this manner. If it is issued on a character, it will delete the character under the cursor.

Spelling Correction

The tc shell can also correct the spelling of commands, user IDs, or file names. Pressing the [ESC] [S] key sequence will tell the shell to check, and if necessary, correct the spelling of the word preceding the cursor. If you wish to correct the spelling of the entire command line, you can use the [ESC] $ key sequence.

Spelling correction can be done automatically with the use of the correct environment variable. A value of cmd will cause the shell to correct the spelling of the command when the [ENTER] key is pressed. If the value is set to all, then the shell will check the spelling of the entire command when the [ENTER] key is pressed. If any part of the command line is misspelled, the shell will display the corrected command line after the prompt specified by the prompt3 shell variable. Answering [Y] will cause the correct line to be executed, and pressing [E] will leave the uncorrected command line in the edit buffer.

History Enhancements

The tc shell will save your history of commands across sessions. This is done by saving the history to a the ~/.history file upon logout. The savehist shell variable lets you specify how many of the commands will be saved in this file. If the histlit variable is set, the shell will save the literal commands instead of the command after all substitutions have been completed.

Automatic Logout Facility

The tc shell will automatically end your session when it senses user inactivity for a specified amount of time. The autologout shell variable lets you specify the amount of time the shell waits before ending your session. The first word of the value assigned to this variable is the number of minutes of activity the shell should allow. The default value is 60 minutes. The second value represents how long the shell should wait before asking for the user's password. If the password is not entered after 5 tries, the account is logged out automatically by the shell. When the shell logs you out, it will display the message auto-logout and not run any of the commands in the ~/.logout file. This option can be disabled by unsetting the shell variable.

Special alias commands

The tc shell also provides the ability to have a command executed before displaying the OS prompt. This is done by using the alias command. The shell has a special command named precmd that can be aliased to the command to be executed before the prompt.

If you wish to have a command executed every so often, you can have the shell do this automatically. Simply alias the periodic command to the command you want executed periodically. The shell will then execute the command every tperiod minutes. The tperiod shell variable specifies the number of minutes between executions. If this variable is set to 0 or unset, it acts as another form of the precmd alias. The beepcmd alias can be used to specify a command to execute whenever the shell attempts to beep the terminal. This is useful if you are using a terminal which can not sound an audible bell.

Formatting the OS Prompt

The tc shell has a fully configurable prompt. This allows you to make your OS prompt appear in a form that is most comforting. The prompt used by the shell is set by the prompt shell variable. It uses a format that is very similar to that used by the C function printf. The table below shows some of the available sequences.

Sequence Brief Description      Sequence         Brief Description
-------------------------------------------------------------------------------
%/  Current working directory       %~  cwd with ~ substitution for $HOME
%c  Trailing component of cwd       %C  Trailing part of cwd
%!  Current history event number    %M  The full machine host name
%m  Host name up to first '.'       %%  A single %
%S  Start standout mode             %s  Stop standout mode
%B  Start boldfacing mode           %b  Stop boldfacing mode
%U  Start underline mode            %u  Stop underline mode
%t  Current time (12 hour format)   %T  Current time (24 hour format)
\c  c is parsed as in bindkey       ^c  c is parsed as with bindkey
%n  The value of the user variable  %#  A # if tcsh is run as root shell
%d  The day in word format          %D  The day number format
%w  The month in word format        %W  The month in number format
%y  The year in two digit format    %Y  The year in four digit format
%l  The line (tty) you are on       %L  Clear from prompt to end of display
%?  Return code from last command   %{..%}  Include str as literal esc sequence

Watching Logins and Logouts

The tc shell can also be used to notify you when a specific user logs onto the system, or when a user logs into a specific terminal. This is done with the watch shell variable. This variable should be assigned the list of userids for which you wish to watch the logins. Each of these userids should be followed by the terminal to watch. Either one of these parameters can be replaced by the keyword any to represent any userid or any terminal. The first argument to this variable should be the number of minutes the shell should wait before checking the system for the specified users.

You can change the message displayed on your terminal by specifying it as the value for the who shell variable. This variable can be set in the similar manner as the prompt variable. The default string is "%n has %a %l." The table below shows some of the possible formatting sequences.

Format  Brief Description            Format       Brief Description
-------------------------------------------------------------------------------
%n  The name of the user watched       %a  The observed action
%l  The line (tty) of the user
%S  Start standout mode                %s  Stop standout mode
%B  Start boldface mode                %b  Stop boldface mode
%U  Start underline mode               %u  Stop underline mode
%M  The full host name of remote host  %m  The host name up to the first '.'
%t  The time in 12 hour format         %T  The time in 24 hour format
%D  The day in dd format               %Y  The year in yy format
%w  The month in word format           %W  The month in number format

Environment Variables

The following list of environment variables have been added to the tc shell. Each variable is followed by a brief description.

Variable         Brief Description
------------------------------------------------------------------------------
HPATH            Path in which to look for command documentation
LANG             Used to give preferred character environment
LC_CTYPE         Used to change ctype character handling
NOREBIND         Inhibits rebinding of printable characters
PATH             Path to look for command execution
SHLVL            Current shell level nesting
TERM             Used to tell what type of terminal is being used
LINES            Number of lines on the terminal
COLUMNS          Number of columns on the terminal
TERMCAP          Terminal capability string
SYSTYPE          The current system type

Shell Variables

The following shell variables are new to the tc shell.
Variable         Brief Description
-------------------------------------------------------------------------------
addsuffix        Add a / for directories and a space for files when completing words
ampm             Show all time in 12 hour format with AM/PM
autocorrect      Correct misspelled words automatically
autoexpand       Invoke the expand history function automatically
autolist         List possibilities on an ambiguous completion
autologout       Specifies how long the shell should wait before logging you out
backslash_quote  Makes the backslash quote \, ', and "
correct          Automatically try to correct the spelling of commands
dextract         Extract a directory on pushd rather than rotating
dunique          Push only directories that are not in the directory stack
echo_style       Set the style of the builtin echo
edit             Use the input editor
fignore          List of file name suffixes to ignore during a complete
gid              The current group id
histlit          If set, history will record the literal command lines
histfile         The file to store the history of commands
inputmode        Can be set to insert or overwrite
listjobs         List all jobs when suspending
listlinks        Resolve symbolic links when listing files
listmax          Maximum number of items to list without asking
matchbeep        Control beeping upon completion
nobeep           Disables beeping completely
nokanji          If kanji support is enabled, this will disable it
nostat           List of directories that should not be stated during a completion
oid              The organization id number
printexitvalue   If an interactive program exits non-zero, print the value
prompt           The prompt to use for command input
prompt2          The string to prompt for while and for loops
prompt3          String to prompt when automatic spelling has corrected a line
pushdtohome      Make pushd with no args do a pushd ~
pushdsilent      Do not print the dir stack on every pushd and popd
recexact         Recognize exact matches even if they are ambiguous
rmstar           Prompt the user before executing an rm * command
savedirs         Before exiting, create a ~/.cshdirs file to store the directory stack
savehist         Number of history commands to store
shlvl            Integer value specifying the number of nested shells
showdots         Show hidden files in list and complete operations
symlinks         Used with symbolic links
tcsh             Holds the current version of the tc shell
term             The terminal type
tperiod          Periodic command wait period in minutes
tty              The name of the tty
uid              The current real user ID
version          The version ID stamp for this tc shell.
visiblebell      Use the visible bell (screen flash) rather than audible bell
watch            List of events to watch
who              Format string for the printouts generated when the watch variable is set
wordchars        list of non-alphanumeric characters considered part of a word

HELPFUL HINTS

You can see the value of user variables by using the set command. The env command can be used to display the values of the system variables.

If you have a long file name, it is easier to type enough characters on the command line to distinguish it from all other files and then press the [TAB] key. This will cause the shell to complete the file name for you.

The following command will make your prompt appear similar to the prompt used by MS-DOS.

     set prompt="%M:%/> "
A prompt similar to that used by the IBM 4381 running ESA can be done by using the string "Ready(%?); %T\n" with the ampm variable unset.

REFERENCES/MANUALS

For more information please see the man pages on the tcsh command.

(c) Copyright UCF Computer Services I& R Support 07/26/93