tcsh — Invoke a C shell


tcsh [–bcdeFfimnqstvVxX]

tcsh –l
Note: –l is a lowercase L, not an uppercase i.


The tcsh shell is an enhanced but completely compatible version of the Berkeley UNIX C shell, tcsh. It is a command language interpreter usable both as an interactive login shell and a shell script command processor. It includes a command-line editor, programmable word completion, spelling correction, a history mechanism, job control, and a C-like syntax.

You can invoke the shell by typing an explicit tcsh command. A login shell can also be specified by invoking the shell with the –l option as the only argument.

A login shell begins by executing commands from the system files /etc/csh.cshrc and /etc/csh.login. It then executes commands from files in the user's home directory: first ~/.tcshrc, then ~/.history (or the value of the histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the value of the dirsfile shell variable). The shell reads /etc/csh.login after /etc/csh.cshrc.

Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on invocation.

Commands like stty, which need be run only once per login, typically go in the user's ~/.login file.

In the normal case, the shell begins reading commands from the terminal, prompting with >. The shell repeatedly reads a line of command input, breaks it into words, places it on the command history list, and then parses and executes each command in the line. See Command execution.

A user can log out of a tcsh shell session by typing ^D, logout, or login on an empty line (see ignoreeof shell variable), or via the shell's autologout mechanism. When a login shell terminates, it sets the logout shell variable to normal or automatic as appropriate, then executes commands from the files /etc/csh.logout and ~/.logout.
Note: The names of the system login and logout files vary from system to system for compatibility with different csh variants; see tcsh files.
Restriction: If the tagged script is being run with automatic conversion enabled, the code page of the locale must be SBCS.


If the first argument (argument 0) to the tcsh shell is - (hyphen), then it is a login shell. You can also specify the login shell by invoking the tcsh shell with the –l as the only argument.

The z/OS UNIX System Services tcsh shell accepts the following options on the command line:
Forces a break from option processing, causing any further shell arguments to be treated as non-option arguments. The remaining arguments will not be interpreted as shell options. This can be used to pass options to a shell script without confusion or possible subterfuge.
Reads and executes commands stored in the command shell (this option must be present and must be a single argument). Any remaining arguments are placed in the argv shell variable.
Loads the directory stack from ~/.cshdirs whether or not it is a login shell.
Terminates shell if any invoked command terminates abnormally or yields a nonzero exit status.
Invokes an interactive shell and prompts for its top-level input, even if it appears to not be a terminal. Shells are interactive without this option if their inputs and outputs are terminals.
Invokes a login shell. Only applicable if –l is the only option specified.
Note: –l is a lowercase L not an uppercase i.
Loads ~/.tcshrc even if it does not belong to the effective user.
Parses commands but does not execute them. This aids in debugging shell scripts.
Accepts SIGQUIT and behaves when it is used under a debugger. Job control is disabled.
Take command input from the standard input.
Reads and executes a single line of input. A \ (backslash) can be used to escape the newline at the end of this line and continue onto another line.
Sets the verbose shell variable so command input is echoed after history substitution.
Sets the verbose shell variable even before executing ~/.tcshrc.
Sets the echo shell variable so commands are echoed immediately before execution.
Is to –x as –V is to –v.

After processing of option arguments, if arguments remain but none of the –c, –i, –s, or –t were given, the first argument is taken as the name of a file of commands, or script , to be executed. The shell opens this file and saves its name for possible resubstitution by $0. Since many systems use shells whose shell scripts are not compatible with this shell, the tcsh shell uses such a standard shell to execute a script whose character is not a #, that is, which does not start with a comment.

Remaining arguments are placed in the argv shell variable.

tcsh shell editing

In this topic, we first describe the Command-Line Editor. We then discuss Completion and Listing and Spelling Correction which describe two sets of functionality that are implemented as editor commands but which deserve their own treatment. Finally, the Editor Commands topic lists and describes the editor commands specific to the tcsh shell and their default bindings.

Command-line editor

Command-line input can be edited using key sequences much like those used in GNU Emacs or vi. The editor is active only when the edit shell variable is set, which it is by default in interactive shells. The bindkey built-in command can display and change key bindings. Emacs-style key bindings are used by default, but bindkey can change the key bindings to vi-style bindings.

The shell always binds the arrow keys to:
unless doing so would alter another single-character binding. To prevent these bindings, set the arrow key escape sequences to the empty string with settc.
Other key bindings are, for the most part, what emacs and vi users would expect and can easily be displayed by bindkey, so there is no need to list them here. Likewise, bindkey can list the editor commands with a short description of each.
Note: Editor commands do not have the same notion of a word as does the tcsh shell. The editor delimits words with any nonalphanumeric characters not in the shell variable wordchars. The tcsh shell recognizes only white space and some of the characters with special meanings to it, listed in Command syntax.

Completion and listing

The tcsh shell is often able to complete words when given a unique abbreviation. Type part of a word (for example ls /usr/lost) and press the tab key to run the complete-word editor command. The shell completes the file name /usr/lost to /usr/lost+found/, replacing the incomplete word with the complete word in the input buffer. (Note the terminal / (forward slash); completion adds a / to the end of completed directories and a space to the end of other completed words, to speed typing and provide a visual indicator of successful completion. The addsuffix shell variable can be unset to prevent this.) If no match is found (for example, /usr/lost+found doesn't exist), the terminal bell rings. If the word is already complete (for example, there is a /usr/lost on your system, or you were thinking too far ahead and typed the whole thing), a / or space is added to the end if it isn't already there.

Completion works anywhere in the line, not just at the end; completed text pushes the rest of the line to the right. Completion in the middle of a word often results in leftover characters to the right of the cursor which need to be deleted.

Commands and variables can be completed in much the same way. For example, typing em [tab] would complete 'em' to 'emacs' if emacs were the only command on your system beginning with 'em'. Completion can find a command in any directory in the path or if given a full path name. Typing echo $ar[tab] would complete '$ar' to '$argv' if no other variable began with 'ar'.

The shell parses the input buffer to determine whether the word you want to complete should be completed as a file name, command or variable. The first word in the buffer and the first word following ';', '|', '|&', '&&' or '||' is considered to be a command. A word beginning with '$' is considered to be a variable. Anything else is a file name. An empty line is completed as a file name.

You can list the possible completions of a word at any time by typing ^D to run the delete-char-or-list-or-eof editor command. The tcsh shell lists the possible completions using the ls-F built-in and reprints the prompt and unfinished command line, for example:
> ls /usr/l['^D]
lbin/ lib/ local/ lost+found/
> ls /usr/l 
If the autolist shell variable is set, the tcsh shell lists the remaining choices (if any) whenever completion fails:
> set autolist
> nm /usr/lib/libt[tab]
libtermcap.a@ libtermlib.a@
> nm /usr/lib/libterm

If autolist is set to ambiguous, choices are listed only if multiple matches are possible, and if the completion adds no new characters to the name to be matched.

A file name to be completed can contain variables, your own or others' home directories abbreviated with ~ (tilde; see File name substitution) and directory stack entries abbreviated with = (equal; see Directory stack substitution). For example:
> ls ~k[^D]
kahn kas kellogg
> ls ~ke[tab]
> ls ~kellogg/


> set local = /usr/local
> ls $lo[tab]
> ls $local/[^D]
bin/ etc/ lib/ man/ src/
> ls $local/
Variables can also be expanded explicitly with the expand-variables editor command.

delete-char-or-list-or-eof only lists at the end of the line; in the middle of a line it deletes the character under the cursor and on an empty line it logs one out or, if ignoreeof is set, does nothing. M-^D, bound to the editor command list-choices, lists completion possibilities anywhere on a line, and list-choices (or any one of the related editor commands which do or don't delete, list and log out, listed under delete-char-or-list-or-eof) can be bound to ^D with the bindkey built-in command if so desired.

The complete-word-fwd and complete-word-back editor commands (not bound to any keys by default) can be used to cycle up and down through the list of possible completions, replacing the current word with the next or previous word in the list.

The tcsh shell variable fignore can be set to a list of suffixes to be ignored by completion. Consider the following:
    > ls
    Makefile condiments.h~ main.o side.c
    README main.c meal side.o
    condiments.h main.c~
    > set fignore = (.o \~)
    > emacs ma[^D]
    main.c main.c~ main.o
    > emacs ma[tab]
    > emacs main.c 
'main.c~' and 'main.o' are ignored by completion (but not listing), because they end in suffixes in fignore. \ is needed in front of ~ to prevent it from being expanded to home as described under File name substitution. fignore is ignored if only one completion is possible.

If the complete shell variable is set to enhance, completion: 1.) ignores case and 2.) considers periods, hyphens and underscores ('.', '-' and '_') to be word separators and hyphens and underscores to be equivalent.

If you had the following files:
comp.lang.c comp.lang.perl comp.std.c++
comp.lang.c++ comp.std.c
and typed mail -f c.l.c[tab], it would be completed to mail -f comp.lang.c, and ^D would list comp.lang.c and comp.lang.c++. mail -f c..c++[^D] would list comp.lang.c++ and comp.std.c++. Typing rm a--file[^D] in the following directory
A_silly_file a-hyphenated-file another_silly_file
would list all three files, because case is ignored and hyphens and underscores are equivalent. Periods, however, are not equivalent to hyphens or underscores.
Completion and listing are affected by several other tcsh shell variables: recexact can be set to complete on the shortest possible unique match, even if more typing might result in a longer match. For example:
> ls
fodder foo food foonly
> set recexact
> rm fo[tab]
just beeps, because 'fo' could expand to 'fod' or 'foo', but if we type another 'o',
> rm foo[tab]
> rm foo 
the completion completes on 'foo', even though 'food' and 'foonly' also match. autoexpand can be set to run the expand-history editor command before each completion attempt, and correct can be set to complete commands automatically after one hits 'return'. matchbeep can be set to make completion beep or not beep in a variety of situations, and nobeep can be set to never beep at all. nostat can be set to a list of directories and patterns which match directories to prevent the completion mechanism from stat(2)ing those directories.
Note: The completion operation succeeds, but faster. The setting of nostat is evident when using the listflags variable. For example:
>set listflags=x>
ls-F /u/pluto
>set nostat=(/u/pluto/)
>ls-F /u/pluto
Although, you must be careful when setting nostat to keep the trailing / (forward slash).
listmax and listmaxrows can be set to limit the number of items and rows (respectively) that are listed without asking first. recognize_only_executables can be set to make the shell list only executables when listing commands, but it is quite slow.

Finally, the complete built-in command can be used to tell the shell how to complete words other than file names, commands and variables. Completion and listing do not work on glob-patterns (see File name substitution), but the list-glob and expand-glob editor commands perform equivalent functions for glob-patterns.

Spelling correction

The tcsh shell can sometimes correct the spelling of file names, commands and variable names as well as completing and listing them.

Individual words can be corrected for spelling with the spell-word editor command (typically bound to M-s and M-S where M = Meta Key or escape (ESC) key) and the entire input buffer with spell-line (typically bound to M-$). The correct shell variable can be set to 'cmd' to correct the command name or 'all' to correct the entire line each time return is typed.

When spelling correction is invoked in any of these ways and the shell thinks that any part of the command line is misspelled, it prompts with the corrected line:
> set correct = cmd
> lz /usr/bin
CORRECT>ls /usr/bin (y|n|e|a)?
where one can answer 'y' or space to execute the corrected line, 'e' to leave the uncorrected command in the input buffer, 'a' to abort the command as if ^C had been pressed, and anything else to execute the original line unchanged.

Spelling correction recognizes user-defined completions (see the complete built-in command). If an input word in a position for which a completion is defined resembles a word in the completion list, spelling correction registers a misspelling and suggests the latter word as a correction. However, if the input word does not match any of the possible completions for that position, spelling correction does not register a misspelling.

Like completion, spelling correction works anywhere in the line, pushing the rest of the line to the right and possibly leaving extra characters to the right of the cursor.

Spelling correction is not guaranteed to work the way one intends, and is provided mostly as an experimental feature.

Editor commands

bindkey lists key bindings and bindkey -l lists and briefly describes editor commands. Only new or especially interesting editor commands are described here. See emacs and vi for descriptions of each editor's key bindings.

The character or characters to which each command is bound by default is given in parentheses. ^character means a control character and M-character a meta character, typed as escape-character on terminals without a meta key. Case counts, but commands which are bound to letters by default are bound to both lower- and uppercase letters for convenience.

Completes a word as described in Completion and listing.
Like complete-word-fwd, but steps up from the end of the list.
Replaces the current word with the first word in the list of possible completions. can be repeated to step down through the list. At the end of the list, beeps and reverts to the incomplete word.
Like complete-word, but ignores user-defined completions.
Copies the previous word in the current line into the input buffer. See also insert-last-word.
Expands the current word to the most recent preceding one for which the current is a leading substring, wrapping around the history list (once) if necessary. Repeating dabbrev-expand without any intervening typing changes to the next previous word etc., skipping identical matches much like history-search-backward does.
delete-char (not bound)
Deletes the character under the cursor. See also delete-char-or-list-or-eof.
delete-char-or-eof (not bound)
Does delete-char if there is a character under the cursor or end-of-file on an empty file. See also delete-char-or-list-or-eof.
delete-char-or-list (not bound)
Does delete-char if there is a character under the cursor or list-choices at the end of the line. See also delete-char-or-list-or-eof.
delete-char-or-list-or-eof (^D)
Does delete-char if there is a character under the cursor, list-choices at the end of the line or end-of-file on an empty line. See also delete-char-or-eof, delete-char-or-list and list-or-eof.
Like up-history, but steps down, stopping at the original input line.
Signals an end of file, causing the tcsh shell to exit unless the ignoreeof shell variable is set to prevent this. See also delete-char-or-list-or-eof.
expand-history (M-space)
Expands history substitutions in the current word. See History substition. See also magic-space, toggle-literal-history, and the autoexpand shell variable.
Expands the glob-pattern to the left of the cursor. For example:
>ls test*[^X-*]
would expand to
>ls test1.c test2.c
if those were the only two files in your directory that begin with 'test'. See File name substitution.
expand-line (not bound)
Like expand-history, but expands history substitutions in each word in the input buffer.
expand-variables (^X-$)
Expands the variable to the left of the cursor. See Variable substitution.
history-search-backward (M-p, M-P)
Searches backwards through the history list for a command beginning with the current contents of the input buffer up to the cursor and copies it into the input buffer. The search string can be a glob-pattern (see File name substitution) containing '*', '?', '[]' or '{}'. up-history and down-history will proceed from the appropriate point in the history list. Emacs mode only. See also history-search-forward and i-search-back.
history-search-forward(M-n, M-N)
Like history-search-backward, but searches forward.
i-search-back (not bound)
Searches backward like history-search-backward, copies the first match into the input buffer with the cursor positioned at the end of the pattern, and prompts with 'bck: ' and the first match. Additional characters can be typed to extend the search. i-search-back can be typed to continue searching with the same pattern, wrapping around the history list if necessary, (i-search-back must be bound to a single character for this to work) or one of the following special characters can be typed:
Appends the rest of the word under the cursor to the search pattern.
delete (or any character bound to backward-delete-char)
Undoes the effect of the last character and deletes a character from the search pattern if appropriate.
If the previous search was successful, aborts the entire search. If not, goes back to the last successful search.
Ends the search, leaving the current line in the input buffer.
Any other character not bound to self-insert-command terminates the search, leaving the current line in the input buffer, and is then interpreted as normal input. In particular, a carriage return causes the current line to be executed. Emacs mode only. See also i-search-fwd and history-search-backward.
Like i-search-back, but searches forward.
insert-last-word (M-_)
Inserts the last word of the previous line (!$) into the input buffer. See also copy-prev-word.
list-choices (M-D)
Lists completion possibilities as described under Completion and listing. See also delete-char-or-list-or-eof.
list-choices-raw (^X-^D)
Like list-choices, but ignores user-defined completions.
list-glob (^X-g, ^X-G)
Lists (via the ls-F) matches to the glob-pattern (see File name substitution) to the left of the cursor.
list-or-eof (not bound)
Does list-choices or end-of-file on an empty line. See also delete-char-or-list-or-eof.
magic-space (not bound)
Expands history substitutions in the current line, like expand-history, and appends a space. magic-space is designed to be bound to the spacebar, but is not bound by default.
normalize-command (^X-?)
Searches for the current word in PATH and, if it is found, replaces it with the full path to the executable. Special characters are quoted. Aliases are expanded and quoted but commands within aliases are not. This command is useful with commands which take commands as arguments, for example, dbx and sh -x.
normalize-path (^X-n, ^X-N)
Expands the current word as described under the expand setting of the symlinks shell variable.
overwrite-mode (unbound)
Toggles between input and overwrite modes.
run-fg-editor (M-^Z)
Saves the current input line and looks for a stopped job with a name equal to the last component of the file name part of the EDITOR or VISUAL environment variables, or, if neither is set, ed or vi. If such a job is found, it is restarted as if fg %job had been typed. This is used to toggle back and forth between an editor and the shell easily. Some people bind this command to ^Z so they can do this even more easily.
run-help (M-h, M-H)
Searches for documentation on the current command, using the same notion of current command as the completion routines, and prints it. There is no way to use a pager; run-help is designed for short help files. Documentation should be in a file named, command.1, command.6, command.8 or command, which should be in one of the directories listed in the HPATH enviroment variable. If there is more than one help file only the first is printed.
self-insert-command (text characters)
In insert mode (the default), inserts the typed character into the input line after the character under the cursor. In overwrite mode, replaces the character under the cursor with the typed character. The input mode is normally preserved between lines, but the inputmode shell variable can be set to insert or overwrite to put the editor in that mode at the beginning of each line. See also overwrite-mode.
sequence-lead-in (arrow prefix, meta prefix, ^X)
Indicates that the following characters are part of a multi-key sequence. Binding a command to a multi-key sequence really creates two bindings: the first character to sequence-lead-in and the whole sequence to the command. All sequences beginning with a character bound to sequence-lead-in are effectively bound to undefined-key unless bound to another command.
spell-line (M-$)
Attempts to correct the spelling of each word in the input buffer, like spell-word, but ignores words whose first character is one of '-', '!', '^' or '%', or which contain '\', '*' or '?', to avoid problems with switches, substitutions and the like. See Spelling correction.
spell-word (M-s, M-S)
Attempts to correct the spelling of the current word as described under Spelling correction. Checks each component of a word which appears to be a path name.
toggle-literal-history (M-r, M-R)
Expands or unexpands history substitutions in the input buffer. See also expand-history and the autoexpand shell variable.
undefined-key (any unbound key)
up-history (up-arrow, ^P)
Copies the previous entry in the history list into the input buffer. If histlit is set, uses the literal form of the entry. Can be repeated to step up through the history list, stopping at the top.
vi-search-back (?)
Prompts with ? for a search string (which can be a glob-pattern, as with history-search-backward), searches for it and copies it into the input buffer. The bell rings if no match is found. Hitting return ends the search and leaves the last match in the input buffer. Hitting escape ends the search and executes the match. vi mode only.
vi-search-fwd (/)
Like vi-search-back, but searches forward.
which-command (M-?)
Does a which (built-in command) on the first word of the input buffer. which displays the command that is executed by the shell after substitutions and path searching. The displayed command has passed access checks by the security product based on the effective ids of the user.

Command syntax

The tcsh shell splits input lines into words at blanks and tabs. The special characters '&', '|', ';', '<', '>', '(', and ')' and the doubled characters '&&', '||', '<<' and '>>' are always separate words, whether or not they are surrounded by white space.

When the tcsh shell's input is not a terminal, the character '#' is taken to begin a comment. Each # and the rest of the input line on which it appears is discarded before further parsing.

A special character (including a blank or tab) can be prevented from having its special meaning, and possibly made part of another word, by preceding it with a backslash (\) or enclosing it in single ( ' ), double ( " ) or backward (' ` ') quotation marks. When not otherwise quoted a newline preceded by a \ is equivalent to a blank, but inside quotes this sequence results in a newline.

Furthermore, all substitutions (see Substitutions) except history substitution can be prevented by enclosing the strings (or parts of strings) in which they appear with single quotation marks or by quoting the crucial characters (for example, '$' or ' `' for variable substitution or command substitution respectively) with \. (alias substitution is no exception: quoting in any way any character of a word for which an alias has been defined prevents substitution of the alias. The usual way of quoting an alias is to precede it with a backslash.) History substitution is prevented by backslashes but not by single quotation marks. Strings quoted with double or backward quotation marks undergo Variable substitution and Command substitution, but other substitutions are prevented.

Text inside single or double quotation marks becomes a single word (or part of one). Metacharacters in these strings, including blanks and tabs, do not form separate words. Only in one special case (see Command substitution) can a double-quoted string yield parts of more than one word; single-quoted strings never do. Backward quotes are special: they signal command substitution, which might result in more than one word.

Quoting complex strings, particularly strings which themselves contain quoting characters, can be confusing. Remember that quotes need not be used as they are in human writing. It might be easier to quote not an entire string, but only those parts of the string which need quoting, using different types of quoting to do so if appropriate.

The backslash_quote shell variable can be set to make backslashes always quote \, ', and ". This might make complex quoting tasks easier, but it can cause syntax errors in csh (or tcsh) scripts.


This topic describes the various transformations the tcsh shell performs on input in the order in which they occur. The topic will cover data structures involved and the commands and variables which affect them. Remember that substitutions can be prevented by quoting as described in Command syntax.

History substitution

Each command, or event, input from the terminal is saved in the history list. The previous command is always saved, and the history shell variable can be set to a number to save that many commands. The histdup shell variable can be set to not save duplicate events or consecutive duplicate events.

Saved commands are numbered sequentially from 1 and stamped with the time. It is not typically necessary to use event numbers, but the current event number can be made part of the prompt by placing an exclamation point (!) in the prompt shell variable.

The shell actually saves history in expanded and literal (unexpanded) forms. If the histlit shell variable is set, commands that display and store history use the literal form.

The history built-in command can print, store in a file, restore and clear the history list at any time, and the savehist and histfile shell variables can be set to store the history list automatically on logout and restore it on login.

History substitutions introduce words from the history list into the input stream, making it easy to repeat commands, repeat arguments of a previous command in the current command, or fix spelling mistakes in the previous command with little typing and a high degree of confidence.

History substitutions begin with the character !. They can begin anywhere in the input stream, but they do not nest. The ! can be preceded by a \ to prevent its special meaning; for convenience, a ! is passed unchanged when it is followed by a blank, tab, newline, = or (. History substitutions also occur when an input line begins with ^. The characters used to signal history substitution (! and ^ (caret)) can be changed by setting the histchars shell variable. Any input line which contains a history substitution is printed before it is executed.

A history substitution can have an event specification, which indicates the event from which words are to be taken, a word designator, which selects particular words from the chosen event, and a modifier, which manipulates the selected words.

An event specification can be
A number, referring to a particular event
An offset, referring to the even n before the current event
The current event. This should be used carefully in csf, where there is no check for recursion. tcsh allows 10 levels of recursion.
The previous event (equivalent to -1)
The most recent event whose first word begins with the string s
The most recent event which contains the string s. The second ? can be omitted if it is immediately followed by a newline.
For example, consider this bit of someone's history list:
9 8:30 nroff -man
10 8:31 cp old
11 8:36 vi
12 8:37 diff
The commands are shown with their event numbers and time stamps. The current event, which we have not typed in yet, is event 13. !11 and !-2 refer to event 11. !! refers to the previous event, 12. !! can be abbreviated ! if it is followed by a : (colon). !n refers to event 9, which begins with n. !?old? also refers to event 12, which contains old. Without word designators or modifiers history references simply expand to the entire event, so we might type !cp to redo the copy command or !!|more if the diff output scrolled off the top of the screen.

History references can be insulated from the surrounding text with braces if necessary. For example, !vdoc would look for a command beginning with vdoc, and, in this example, not find one, but !{v}doc would expand unambiguously to vi wumpus.mandoc. Even in braces, history substitutions do not nest.

While csh expands, for example, !3d to event 3 with the letter d appended to it, tcsh expands it to the last event beginning with 3d; only completely numeric arguments are treated as event numbers. This makes it possible to recall events beginning with numbers. To expand !3d as in csh say !\3d.

To select words from an event we can follow the event specification by a : (colon) and a designator for the desired words. The words of an input line are numbered from 0, the first (typically command) word being 0, the second word (first argument) being 1, etc. The basic word designators are:
The first command word
The nth argument
The first argument, equivalent to 1
The last argument
The word matched by an ?s? search
A range of words
Equivalent to 0–y
Equivalent to ^–$, but returns nothing if the event contains only 1 word
Equivalent to x-$
Equivalent to x*, but omitting the last word ($)
Selected words are inserted into the command line separated by single blanks. For example, the diff command in the previous example might have been typed as diff !!:1.old !!:1(using :1 to select the first argument from the previous event) or diff !-2:2 !-2:1to select and swap the arguments from the cp command. If we didn't care about the order of the diff we might have said diff !-2:1-2or simply diff !-2:*. The cp command might have been written cp !#:1.old, using # to refer to the current event. !n:- would reuse the first two words from the nroff command to say nroff -man

The : separating the event specification from the word designator can be omitted if the argument selector begins with a '^', '$', '*', '%' or '-'. For example, our diff command might have been diff !!^.old !!^ or, equivalently, diff !!$.old !!$. However, if !! is abbreviated !, an argument selector beginning with - (hyphen) will be interpreted as an event specification.

A history reference can have a word designator but no event specification. It then references the previous command. Continuing our diff example, we could have said simply diff !^.old !^or, to get the arguments in the opposite order, just diff !*.

The word or words in a history reference can be edited, or modified, by following it with one or more modifiers, each preceded by a : (colon):
Remove a trailing path name component, leaving the head.
Remove all leading path name components, leaving the tail.
Remove a file name extension .xxx, leaving the root name.
Remove all but the extension
Uppercase the first lowercase letter.
Lowercase the first uppercase letter.
Substitute l for r. l is simply a string like r, not a regular expression as in the eponymous ed command. Any character can be used as the delimiter in place of /; a \ can be used to quote the delimiter inside l and r. The character & in the r is replaced by l; \ also quotes &. If l is empty (''''), the l from a previous substitution or the s from a previous ?s? event specification is used. The trailing delimiter can be omitted if it is immediately followed by a newline.
Repeat the previous substitution
Apply the following modifier once to each word.
Apply the following modifier as many times as possible to a single word. 'a' and 'g' can be used together to apply a modifier globally. In the current implementation, using the 'a' and 's' modifiers together can lead to an infinite loop. For example, :as/f/ff/ will never terminate. This behavior might change in the future.
Print the new command line but do not execute it.
Quote the substituted words, preventing further substitutions.
Like q, but break into words at blanks, tabs and newlines.
Modifiers are applied only to the first modifiable word (unless 'g' is used). It is an error for no word to be modifiable.

For example, the diff command might have been written as diff !#^:r, using :r to remove .old from the first argument on the same line (!#^). We could say echo hello out there, then echo !*:u to capitalize 'hello', echo !*:au to say it out loud, or echo !*:agu to really shout. We might follow mail -s "I forgot my password" rot with !:s/rot/root to correct the spelling of 'root' (but see Spelling correction for a different approach).

There is a special abbreviation for substitutions. ^, when it is the first character on an input line, is equivalent to !:s^. Thus, we might have said ^rot^root to make the spelling correction in the previous example. This is the only history substitution which does not explicitly begin with !.

In csh as such, only one modifier can be applied to each history or variable expansion. In tcsh, more than one can be used, for example
% mv /usr/man/man1/wumpus.1
% man !$:t:r
man wumpus
In csh, the result would be wumpus.1:r. A substitution followed by a colon might need to be insulated from it with braces:
> mv a.out /usr/games/wumpus
> setenv PATH !$:h:$PATH
Bad ! modifier: $.
> setenv PATH !{-2$:h}:$PATH
setenv PATH /usr/games:/bin:/usr/bin:.
The first attempt would succeed in csh but fails in tcsh, because tcsh expects another modifier after the second colon instead of $.
Finally, history can be accessed through the editor as well as through the substitutions just described. The following commands search for events in the history list and compile them into the input buffer:
  • up-history
  • down-history
  • history-search-backward
  • history-search-forward
  • i-search-back
  • i-search-fwd
  • vi-search-back
  • vi-search-fwd
  • copy-prev-word
  • insert-last-word
The toggle-literal-history editor command switches between the expanded and literal forms of history lines in the input buffer. expand-history and expand-line expand history substitutions in the current word and in the entire input buffer respectively.

Alias substitution

The shell maintains a list of aliases which can be set, unset, and printed by the alias and unalias commands. After a command line is parsed into simple commands (see Command execution) the first word of each command, left-to-right, is checked to see if it has an alias. If so, the first word is replaced by the alias. If the alias contains a history reference, it undergoes history substitution as though the original command were the previous input line. If the alias does not contain a history reference, the argument list is left untouched.

Thus if the alias for ls were ls -l the command ls /usrwould become ls -l /usr, the argument list here being undisturbed. If the alias for lookup were grep !^ /etc/passwd then lookup bill would become grep bill /etc/passwd. Aliases can be used to introduce parser metasyntax. For example, alias print 'pr \!* | lpr' defines a command (print) which prints its arguments to the line printer.

Alias substitution is repeated until the first word of the command has no alias. If an alias substitution does not change the first word (as in the previous example) it is flagged to prevent a loop. Other loops are detected and cause an error.

Some aliases are referred to by the shell; see tcsh built-in commands.

Variable substitution

The tcsh shell maintains a list of variables, each of which has as value a list of zero or more words. The values of tcsh shell variables can be displayed and changed with the set and unset commands. The system maintains its own list of "environment" variables. These can be displayed and changed with printenv, setenv and unsetenv.

Variables can be made read-only with set -r. Read-only variables cannot be modified or unset; attempting to do so will cause an error. Once made read-only, a variable cannot be made writable, so set -r should be used with caution. Environment variables cannot be made read-only.

Some variables are set by the tcsh shell or referred to by it. For instance, the argv variable is an image of the shell's argument list, and words of this variable's value are referred to in special ways. Some of the variables referred to by the tcsh shell are toggles; the shell does not care what their value is, only whether they are set or not. For instance, the verbose variable is a toggle which causes command input to be echoed. The -v command line option sets this variable. Special shell variables lists all variables which are referred to by the shell.

Other operations treat variables numerically. The @ (at) command permits numeric calculations to be performed and the result assigned to a variable. Variable values are, however, always represented as (zero or more) strings. For the purposes of numeric operations, the null string is considered to be zero, and the second and subsequent words of multiword values are ignored.

After the input line is aliased and parsed, and before each command is executed, variable substitution is performed keyed by $ characters. This expansion can be prevented by preceding the $ with a \ except within double quotation marks (") where it always occurs, and within single quotation marks ( ' ) where it never occurs. Strings quoted by backward quotation marks or accents (`) are interpreted later (see Command substitution) so $ substitution does not occur there until later, if at all. A $ is passed unchanged if followed by a blank, tab, or end-of-line.

Input/output redirections are recognized before variable expansion, and are variable expanded separately. Otherwise, the command name and entire argument list are expanded together. It is thus possible for the first (command) word (to this point) to generate more than one word, the first of which becomes the command name, and the rest of which become arguments.

Unless enclosed in double quotation marks (") or given the :q modifier the results of variable substitution can eventually be command and file name substituted. Within ", a variable whose value consists of multiple words expands to a (portion of a) single word, with the words of the variable's value separated by blanks. When the :q modifier is applied to a substitution the variable will expand to multiple words with each word separated by a blank and quoted to prevent later command or file name substitution.

The following metasequences are provided for introducing variable values into the shell input. Except as noted, it is an error to reference a variable which is not set.
Substitutes only the selected words from the value of name. The selector is subjected to $ substitution and can consist of a single number or two numbers separated by a - (hyphen). The first word of a variable's value is numbered 1. If the first number of a range is omitted it defaults to 1. If the last member of a range is omitted it defaults to $#name. The selector * selects all words. It is not an error for a range to be empty if the second argument is omitted or in range.
Substitutes the name of the file from which command input is being read. An error occurs if the name is not known.
Equivalent to $argv[number].
Equivalent to $argv, which is equivalent to $argv[*].
The : (colon) modifiers described in History substition, except for :p, can be applied to the Variable substitution. More than one can be used. Braces might be needed to insulate a variable substitution from a literal colon just as with history substitution; any modifiers must appear within the braces. The following substitutions cannot be modified with : modifiers.
Substitutes the string 1 if name is set, 0 if it is not.
Substitutes the name of the file from which command input is being read. An error occurs if the name is not known.
Substitutes 1 if the current input file name is known, 0 if it is not. Always 0 in interactive shells.
$#name or ${#name}
Substitutes the number of words in name.
Equivalent to '$#argv'.
Substitutes the number of characters in name.
Substitutes the number of characters in $argv[number].
Equivalent to $status.
Substitutes the (decimal) process number of the (parent) shell.
Substitutes the (decimal) process number of the last background process started by this shell.
Substitutes a line from the standard input, with no further interpretation thereafter. It can be used to read from the keyboard in a shell script. While csh always quotation marks $<, as if it were equivalent to $<:q, tcsh does not. Furthermore, when tcsh is waiting for a line to be typed the user can type an interrupt to interrupt the sequence into which the line is to be substituted, but csh does not allow this.
The editor command expand-variables, normally bound to ^X-$, can be used to interactively expand individual variables.

The remaining substitutions are applied selectively to the arguments of tcsh built-in commands. This means that portions of expressions which are not evaluated are not subjected to these expansions. For commands which are not internal to the tcsh shell, the command name is substituted separately from the argument list. This occurs very late, after input-output redirection is performed, and in a child of the main shell.

Command substitution

Command substitution is indicated by a command enclosed in ' ' '. The output from such a command is broken into separate words at blanks, tabs and newlines, and null words are discarded. The output is variable and command substituted and put in place of the original string.

Command substitutions inside double quotation marks ( " ) retain blanks and tabs; only newlines force new words. The single final newline does not force a new word in any case. It is thus possible for a command substitution to yield only part of a word, even if the command outputs a complete line.

File name substitution

If a word contains any of the characters '*', '?', '[' or '{' or begins with the character '~' it is a candidate for file name substitution, also known as globbing. This word is then regarded as a pattern (glob-pattern), and replaced with an alphabetically sorted list of file names which match the pattern.

In matching file names, the character . (period) at the beginning of a file name or immediately following a / (forward slash), as well as the character / must be matched explicitly. The character * matches any string of characters, including the null string. The character ? matches any single character. The sequence […] matches any one of the characters enclosed. Within […], a pair of characters separated by - matches any character lexically between the two.

Some glob-patterns can be negated: The sequence [^…] matches any single character not specified by the characters and ranges of characters in the braces.

An entire glob-pattern can also be negated with ^:
> echo *
bang crash crunch ouch
> echo ^cr*
bang ouch
Glob-patterns which do not use '?', '*', or'[]' or which use '{}' or '^' are not negated correctly.

The metanotation a{b,c,d}e is a shorthand for abe ace ade. Left-to-right order is preserved: /usr/source/s1/{oldls,ls}.c expands to /usr/source/s1/oldls.c /usr/source/s1/ls.c. The results of matches are sorted separately at a low level to preserve this order, such as, like the following example, where ../{memo,*box} might expand to ../memo ../box ../mbox. (Note that 'memo' was not sorted with the results of matching '*box'.) It is not an error when this construct expands to files which do not exist, but it is possible to get an error from a command to which the expanded list is passed. This construct can be nested. As a special case the words {, } and {} are passed undisturbed. The character ~ at the beginning of a file name refers to home directories. Standing alone, for example, ~, it expands to the invoker's home directory as reflected in the value of the home shell variable. When followed by a name consisting of letters, digits and - (hyphen) characters the shell searches for a user with that name and substitutes their home directory; thus ~ken might expand to /usr/ken and ~ken/chmach to /usr/ken/chmach. If the character ~ is followed by a character other than a letter or / or appears elsewhere than at the beginning of a word, it is left undisturbed. A command like setenv MANPATH /usr/man:/usr/local/man:~/lib/man does not, therefore, do home directory substitution as one might hope. It is an error for a glob-pattern containing '*', '?', '[' or '~', with or without '^', not to match any files. However, only one pattern in a list of glob-patterns must match a file (so that, for example, rm *.a *.c *.o would fail only if there were no files in the current directory ending in '.a', '.c', or '.o'), and if the nonomatch shell variable is set a pattern (or list of patterns) which matches nothing is left unchanged instead of causing an error.

The noglob shell variable can be set to prevent file name substitution, and the expand-glob editor command, normally bound to ^X-*, can be used to interactively expand individual file name substitutions.

Directory stack substitution

The directory stack is a list of directories, numbered from zero, used by the pushd, popd and dirs built-in commands for tcsh. dirs can print, store in a file, restore, and clear the directory stack at any time, and the savedirs and dirsfile shell variables can be set to store the directory stack automatically on logout and restore it on login. The dirstack shell variable can be examined to see the directory stack and set to put arbitrary directories into the directory stack.

The character = (equal) followed by one or more digits expands to an entry in the directory stack. The special case =- expands to the last directory in the stack. For example,
    > dirs -v
    0 /usr/bin
    1 /usr/spool/uucp
    2 /usr/accts/sys
    > echo =1
    > echo =0/calendar
    > echo =-
The noglob and nonomatch shell variables and the expand-glob editor command apply to directory stack as well as file name substitutions.

Other substitutions

There are several more transformations involving file names, not strictly related to the Directory stack substitution, but mentioned here for completeness. Any file name can be expanded to a full path when the symlinks variable is set to expand. Quoting prevents this expansion, and the normalize-path editor command does it on demand. The normalize-command editor command expands commands in PATH into full paths on demand. Finally, cd and pushd interpret - (hyphen) as the old working directory (equivalent to the tcsh shell variable owd). This is not a substitution at all, but an abbreviation recognized only by those commands. Nonetheless, it too can be prevented by quoting.

Command execution

The next three topics describe how the shell executes commands and deals with their input and output.

Built-in and non-built-in command execution

Built-in commands for tcsh are executed within the shell. If any component of a pipeline except the last is a built-in command, the pipeline is executed in a subshell.

Parenthesized commands are always executed in a subshell:
(cd; pwd); pwd
which prints the home directory, leaving you where you were (printing this after the home directory), while
cd; pwd
leaves you in the home directory. Parenthesized commands are most often used to prevent cd from affecting the current shell.

When a command to be executed is found not to be a built-in command the tcsh shell attempts to execute the command via execve. Each word in the variable path names a directory in which the tcsh shell will look for the command. If it is given neither a -c nor a -t option, the shell hashes the names in these directories into an internal table so that it will only try an execve in a directory if there is a possibility that the command resides there. This greatly speeds command location when a large number of directories are present in the search path. If this mechanism has been turned off (via unhash), if the shell was given a -c or -t argument or in any case for each directory component of path which does not begin with a /, the shell concatenates the current working directory with the given command name to form a path name of a file which it then attempts to execute.

If the file has execute permissions but is not an executable to the system (that is, it is neither an executable binary nor a script which specifies its interpreter), then it is assumed to be a file containing shell commands and a new shell is spawned to read it. The shell special alias can be set to specify an interpreter other than the shell itself.

Input or output

The standard input and standard output of a command can be redirected with the following syntax listed in Table 1.

Table 1. Standard input/output syntax for the tcsh shell
Syntax Description
< name Open file name (which is first variable, command and file name expanded) as the standard input.
<< word Read the shell input up to a line which is identical to word. word is not subjected to variable, file name or command substitution, and each input line is compared to word before any substitutions are done on this input line. Unless a quoting \, " , ' ' or ' ' ' appears in word variable and command substitution is performed on the intervening lines, allowing \ to quote $, \ and ' (single quotation mark). Commands which are substituted have all blanks, tabs, and newlines preserved, except for the final newline which is dropped. The resultant text is placed in an anonymous temporary file which is given to the command as standard input.

> name
>! name>
& name
>&! name

The file name is used as standard output. If the file does not exist then it is created; if the file exists, its is overwritten and, therefore, the previous contents are lost.

If the shell variable noclobber is set, then the file must not exist or be a character special file (for example, a terminal or /dev/null) or an error results. This helps prevent accidental destruction of files. In this case the ! forms can be used to suppress this check.

The forms involving & (ampersand) route the diagnostic output into the specified file as well as the standard output. name is expanded in the same way as < input file names are.

>> name
>>& name>>
! name>
>&! name

Like >, but appends output to the end of name. If the shell variable noclobber is set, then it is an error for the file not to exist, unless one of the ! forms is given.

A command receives the environment in which the shell was invoked as modified by the input-output parameters and the presence of the command in a pipeline. Thus, unlike some previous shells, commands run from a file of shell commands have no access to the text of the commands by default; instead they receive the original standard input of the shell. The << mechanism should be used to present inline data. This permits shell command scripts to function as components of pipelines and allows the shell to block read its input. The default standard input for a command run detached is not the empty file /dev/null, but the original standard input of the shell. If this is a terminal and if the process attempts to read from the terminal, then the process will block and the user is notified (see Jobs).

Diagnostic output can be directed through a pipe with the standard output. Simply use the form |& instead of just |.

The shell cannot presently redirect diagnostic output without also redirecting standard output, but (command > output-file) >& error-file is often an acceptable workaround. Either output-file or error-file can be /dev/tty to send output to the terminal.


Having described how the shell accepts, parses and executes command lines, we now turn to a variety of its useful features.

Control flow

The tcsh shell contains a number of commands which can be used to regulate the flow of control in command files (shell scripts) and (in limited by useful ways) from terminal output. These commands all operate by forcing the shell to reread or skip in its input and, due to the implementation, restrict the placement of some of the commands.

The foreach, switch, and while statements, as well as the if-then-else form of the if statement, require that the major keywords appear in a single simple command on an input line.

If the shell's input is not seekable, the shell buffers up input whenever a loop is being read and performs seeks in this internal buffer to accomplish the rereading implied by the loop . (To the extent that this allows, backward gotos will succeed on non-seekable inputs.)


The if, while, and exit built-in commands use expressions with a common syntax. The expressions can include any of the operators described in the next three topics. Note that the @ built-in command has its own separate syntax.

Logical, arithmetical, and comparison operators

These operators are similar to those of C and have the same precedence. They include:
|| && | ^ & == !=  =~  !~  <=  >=
< > << >>  + - * / % ! ~ (  )
Here the precedence increases to the right, '==' '!=' '=~' and '!~', '<=' '>=' '<' and '>', '<<' and '>>', '+' and '-', '*' / and '%' being in groups, at the same level. The '==' '!=' '=~' and '!~' operators compare their arguments as strings; all others operate on numbers. The operators '=~' and '!~' are like '!=' and '==' except that the right hand side is a glob-pattern (see File name substitution) against which the left hand operand is matched. This reduces the need for use of the switch built-in command in shell scripts when all that is really needed is pattern matching.

Strings that begin with 0 are considered octal numbers. Null or missing arguments are considered 0. The results of all expressions are strings, which represent decimal numbers. It is important to note that no two components of an expression can appear in the same word; except when adjacent to components of expressions which are syntactically significant to the parser ('$' '|' '<' '>' '(' ')') they should be surrounded by spaces.

Command exit status

Commands can be executed in expressions and their exit status returned by enclosing them in braces ({}). The braces must be separated from the words of the command by spaces. Command executions succeed, returning true, that is, 1, if the command exits with status 0, otherwise they fail, returning false (0). If more detailed status information is required, then the command should be executed outside of an expression and the status shell variable examined.

File inquiry operators

Some of these operators perform true/false tests on files and related objects. They are of the form -op file, where op is one of:
An extended ACL of type c exists. Character c represents the type of ACL:
Access ACL
Directory default ACL
File default ACL
Testing with suboptions d and f will always return false for files (files do not have default ACLs).
Read access (as determined by security product and effective ids)
Write access (as determined by security product and effective ids)
Execute access (as determined by security product and effective ids)
Executable in the path or shell built-in. For example, –X ls and –X ls-F are generally true, but –X /bin/ls is not. (This is determined by security product and effective ids.)
File has the APF extended attribute
File has the program
File has the shared address space extended attribute
File has the shared library extended attribute
Zero size
Nonzero size
Plain file
Symbolic link
Block special file
Character special file
Named pipe (fifo)
Socket special file
Set-user ID bit is set
Set-group-ID bit is set
Sticky bit is set
t file_descriptor (which must be a digit) is an open file descriptor for a terminal device
Applies subsequent operators in a multiple-operator test to a symbolic link instead of to the file to which the link points
file is command and file name expanded and then tested to see if it has the specified relationship to the real user. If file does not exist or is inaccessible or, for the operators indicated by *, if the specified file type does not exist on the current system, then all inquiries return false (0).

These operators can be combined for conciseness: –xy file is equivalent to –x file && –y file. For example, –fx is true (returns 1) for plain executable files, but not for directories.

L can be used in a multiple-operator test to apply subsequent operators to a symbolic link instead of to the file to which the link points. For example, -lLo is true for links owned by the invoking user. Lr, Lw, and Lx are always ture for links and false for non-links. L has a different meaning when it is the last operator in a multiple-operator test.

It is possible but not useful, and sometimes misleading, to combine operators which expect file to be a file with operators which do not (for example, X and t). Following L with a non-file operator can lead to particularly strange results.

Other operators return other information, that is not just 0 or 1. They have the same format as before where op can be one of:
Last file access time, as the number of seconds since epoch
Like A, but in timestamp format, that is, 'Fri May 14 16:36:10 1993'
Last file modification time
Like M, but in timestamp format
Last inode modification time
Like C, but in timestamp format
Device number
Inode number
Composite file identifier, in the form device : inode
The name of the file pointed to by a symbolic link
Number of (hard) links
Permissions, in octal, without leading zero
Like P, with leading zero
P mode
Equivalent to -P mode & file, that is, -P22 file returns 22 if file is writable by group and other, 20 if by group only, and 0 if by neither.
P mode:
Like P mode, with leading zero
Numeric userid
Username, or the numeric user ID if the username is unknown
Numeric group ID
Group name, or the numeric group ID if the group name is unknown
Size in bytes
m file
Returns the security label of the file if one exists. Otherwise, returns false.
Only one of these operators can appear in a multiple-operator test, and it must be the last. L has a different meaning at the end of and elsewhere in a multiple-operator test. Because 0 is a valid return value for many of these operators, they do not return 0 when they fail: most return -1, and F returns : (colon).

File inquiry operators can also be evaluated with the filetest built-in command.

File inquiry operators for use with file tagging and the filetest built-in command

–B file
  • True if the file is tagged as binary
  • False if the file is not tagged or tagged as text
  • Returns codeset if the file is tagged as mixed text and binary, that is, txtflag = OFF and codeset stored in file tag
–T file
  • False if the file is not tagged or if it is tagged as txtflag = OFF
  • Returns codeset if the file is tagged as text
Either –B file or –T file will allow a tcsh "if test" to evaluate to true when the file is tagged as indicated. These two operators will also allow tcsh to test for a specific codeset. For example,
if ( -T file == IBM-1047 )  #True if tagged as IBM-1047 text
if ( -B file )              #True if tagged as binary
Note: Code sets that are aliases of each other exist which might cause the test to fail, because the file inquiry operator might return an alias of the code set that you are testing.


The shell associates a job with each pipeline. It keeps a table of current jobs, printed by the jobs command, and assigns them small integer numbers. When a job is started asynchronously with & (ampersand), the shell prints a line which looks like
[1] 1234
indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process id was 1234.

If you are running a job and want to do something else you can press the suspend key (typically ^Z), which sends a STOP signal to the current job. The shell will then normally indicate that the job has been 'Suspended' and print another prompt. If the listjobs shell variable is set, all jobs is listed like the jobs built-in command; if it is set to 'long' the listing is in long format, like jobs -l. You can then manipulate the state of the suspended job. You can put it in the background with the bg command or run some other commands and eventually bring the job back into the foreground with fg. (See also the run-fg-editor editor command.) A ^Z takes effect immediately and is like an interrupt in that pending output and unread input are discarded when it is typed. The wait built-in command causes the shell to wait for all background jobs to complete.

The ^] key sends a delayed suspend signal, which does not generate a STOP signal until a program attempts to read it, to the current job. This can be typed ahead when you have prepared some commands for a job that you want to stop after it has read them. The ^Y key performs this function in csh; in tcsh , ^Y is an editing command.

A job being run in the background stops if it tries to read from the terminal. Background jobs are typically allowed to produce output, but this can be disabled by giving the command stty tostop. If you set the stty option, then background jobs will stop when they try to produce output like they do when they try to read input.

There are several ways to refer to jobs in the shell. The character % introduces a job name. If you want to refer to job number 1, you can name it as %1. Just naming a job brings it to the foreground; thus %' is a synonym for fg %1, bringing job 1 back into the foreground. Similarly, saying %1 & resumes job 1 in the background, just like bg %1. A job can also be named by an unambiguous prefix of the string typed in to start it: %ex would normally restart a suspended ex job, if there were only one suspended job whose name began with the string 'ex'. It is also possible to say %? string to specify a job whose text contains string , if there is only one such job.

The shell maintains a notion of the current and previous jobs. In output pertaining to jobs, the current job is marked with a + (plus) and the previous job with a - (hyphen). The abbreviations %+, %, and (by analogy with the syntax of the history mechanism) %% all refer to the current job, and %- refers to the previous job.

The job control mechanism requires that the stty option new be set on some systems. It is an artifact from a new implementation of the tty driver which allows generation of interrupt characters from the keyboard to tell jobs to stop. See stty and the setty tcsh built-in command for details on setting options in the new tty driver.

Status reporting

The tcsh shell learns immediately whenever a process changes state. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only just before it prints a prompt. This is done so that it does not otherwise disturb your work. If, however, you set the shell variable notify, the shell will notify you immediately of changes of status in background jobs. There is also a shell command notify which marks a single process so that its status changes are immediately reported. By default notify marks the current process; simply say 'notify' after starting a background job to mark it.

When you try to leave the shell while jobs are stopped, you are warned that 'You have stopped jobs.' You can use the jobs command to see what they are. If you do this or immediately try to exit again, the shell will not warn you a second time and the suspended jobs are terminated.

Automatic, periodic, and timed events

There are various ways to run commands and take other actions automatically at various times in the life cycle of the shell.

National language system report

When using the system's multicultural support, the setlocale function is called to determine appropriate character classification and sorting. This function typically examines the LANG and LC_CTYPE environment variables; refer to the system documentation for further details.

Unknown characters (those that are neither printable nor control characters) are printed in the format \nnn.

The version shell variable indicates what options were chosen when the shell was compiled. Note also the newgrp built-in and echo_style shell variable and the locations of the shell's input files (see tcsh files).

Restriction: The tcsh shell currently does not support three locales. They are IBM-1388 (Chinese), IBM-933 (Korean) and IBM-937 (Traditional Chinese).

Handling signals

Login shells ignore interrupts when reading the file ~/.logout.The shell ignores quit signals unless started with -q. Login shells catch the terminate signal, but non-login shells inherit the terminate behavior from their parents. Other signals have the values which the shell inherited from its parent.

In shell scripts, the shell's handling of interrupt and terminate signals can be controlled with onintr, and its handling of hangups can be controlled with hup and nohup.

The shell exits on a hangup (see also the logout shell variable). By default, the shell's children do too, but the shell does not send them a hangup when it exits. hup arranges for the shell to send a hangup to a child when it exits, and nohup sets a child to ignore hangups.

Managing terminals

The shell uses three different sets of terminal (tty) modes: edit, used when editing, quote, used when quoting literal characters, and execute, used when executing commands. The shell holds some settings in each mode constant, so commands which leave the tty in a confused state do not interfere with the shell. The shell also matches changes in the speed and padding of the tty. The list of tty modes that are kept constant can be examined and modified with the setty built-in. Although the editor uses CBREAK mode (or its equivalent), it takes typed-ahead characters anyway.

The echotc, settc and telltc commands can be used to manipulate and debug terminal capabilities from the command line.

The tcsh shell adapts to window resizing automatically and adjusts the environment variables LINES and COLUMNS if set.

tcsh built-in commands

The following table lists the tcsh built-in commands, which are not /bin/sh built-ins.

Other tcsh built-in commands are also found in the z/OS shell. In some cases, they might differ in function; see the specific command description for a discussion of the tcsh version of the command.

As well as built-in commands, the tcsh shell has a set of special aliases:
  • beepcmd
  • cwdcmd
  • periodic
  • precmd
  • shell
If set, each of these aliases executes automatically at the indicated time. They are initially undefined. For more information about aliases, see Alias substitution.
Descriptions of these aliases are as follows:
Runs when the shell wants to ring the terminal bell.
Runs after every change of working directory. For example, if the user is working on an X window system using xterm and a re-parenting window manager that supports title bars such as twm and does
> alias cwdcmd 'echo -n "^[]2;${HOST}:$cwd ^G"'
then the shell will change the title of the running xterm to be the name of the host, a colon, and the full current working directory. A fancier way to do that is
> alias cwdcmd 'echo -n "^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"'
This will put the hostname and working directory on the title bar but only the hostname in the icon manager menu. Putting a cd, pushd or popd in cwdcmd might cause an infinite loop.
Runs every tperiod minutes. This provides a convenient means for checking on common but infrequent changes such as new mail. For example, if one does
        > set tperiod = 30
        > alias periodic checknews
then the checknews program runs every 30 minutes. If periodic is set but tperiod is unset or set to 0, periodic behaves like precmd.
Runs just before each prompt is printed. For example, if one does
> alias precmd date
then date runs just before the shell prompts for each command. There are no limits on what precmd can be set to do, but discretion should be used.
Specifies the interpreter for executable scripts which do not themselves specify an interpreter. The first word should be a full path name to the interpreter. For example: /bin/tcsh or /usr/local/bin/tcsh (by default, this is set to /bin/tcsh).

tcsh shell and environment variables

The variables described in this topic have special meaning to the tcsh shell. The tcsh shell sets addsuffix, argv, autologout, command, echo_style, edit, gid, group, home, loginsh, path, prompt, prompt2, prompt3, shell, shlvl, tcsh, term, tty, uid, user, and version at startup. They do not change thereafter, unless changed by the user. The tcsh shell updates cwd, dirstack, owd, and status when necessary, and sets logout on logout.

The shell synchronizes group, home, path, shlvl, term, and user with the environment variables of the same names: whenever the environment variable changes the shell changes the corresponding shell variable to match (unless the shell variable is read-only) and vice versa. Although cwd and PWD have identical meanings, they are not synchronized in this manner.

The shell automatically interconverts the different formats of path and PATH.

Table 2. tcsh built-in shell variables
Variable Purpose
addsuffix If set, file name completion adds / to the end of directories and a space to the end of normal files.
ampm This variable gives a user the ability to alter the time format in their tcsh prompt. Specifically, ampm will override the %T and %P formatting sequences in a user's prompt. If set, all times are shown in 12hour AM/PM format.
argv The arguments to the shell. Positional parameters are taken from argv. For example, $1 is replaced by $argv. Set by default, but typically empty in interactive shells.
autocorrect If set, the spell-word editor command is invoked automatically before each completion. (This variable is not implemented.)
autoexpand If set, the expand-history editor command is invoked automatically before each completion attempt.
autolist If set, possibilities are listed after an ambiguous completion. If set to ambiguous, possibilities are listed only when no new characters are added by completion.
autologout Set to the number of minutes of inactivity before automatic logout. Automatic locking is an unsupported feature on the z/OS platform. If you specify a second parameter on the autologout statement (intending it to be for autolock), this parameter will be assigned to autologout. When the shell automatically logs out, it prints 'autologout', sets the variable logout to automatic and exits. Set to 60 (automatic logout after 60 minutes) by default in login and superuser shells, but not if the shell thinks it is running under a window system (the DISPLAY environment variable is set), or the tty is a pseudo-tty (pty). See also the logout shell variable.
backslash_ quote If set, backslashes (\) always quote \, ' (single quotation mark) and " (double quotation mark). This might make complex quoting tasks easier, but it can cause syntax errors in csh scripts.
cdpath A list of directories in which cd should search for subdirectories if they aren't found in the current directory.
command If set, the command which was passed to the shell with the -c flag.
complete If set to enhance, completion first ignores case and then considers periods, hyphens and underscores ('.', '-' and '_') to be word separators and hyphens and underscores to be equivalent.
correct If set to cmd, commands are automatically spelling-corrected. If set to complete, commands are automatically completed. If set to all, the entire command line is corrected.
cwd The full path name of the current directory. See also the dirstack and owd shell variables.
dextract If set, pushd +n extracts the nth directory from the directory stack instead of rotating it to the top.
dirsfile The default location in which dirs -S and dirs -L look for a history file. If unset, ~/.cshdirs is used. Because only ~/.tcshrc is normally sourced before ~/.cshdirs, dirsfile should be set in ~/.tcshrc instead of ~/.login.
For example:
set dirsfile = ~/.cshdirs
dirstack An array of all the directories on the directory stack. $dirstack[1] is the current working directory, $dirstack[2] the first directory on the stack, etc. Note that the current working directory is $dirstack[1] but =0 in directory stack substitutions, etc. One can change the stack arbitrarily by setting dirstack, but the first element (the current working directory) is always correct. See also the cwd and owd shell variables.
dunique If set, pushd removes any instances of name from the stack before pushing it onto the stack.
echo If set, each command with its arguments is echoed just before it is executed. For non-built-in commands all expansions occur before echoing. Built-in commands are echoed before command and file name substitution, since these substitutions are then done selectively. Set by the -x command line option.
echo_style The style of the echo built-in. Can be set to:
Don't echo a newline if the first argument is -n.
Recognize backslashed escape sequences in echo strings.
Recognizes both the -n flag and backslashed escape sequences; the default.
Recognize neither.
Set to both by default to the local system default.
The following is an example of this variable's use:
 > echo $echo_style
 > echo "\n"
 > echo -n "test"
 > set echo_style=sysv
 > echo $echo_style
 > echo "\n"

 > echo -n "test"
 -n test
 > set echo_style=both
 > echo $echo_style
 > echo -n "test"
 test> echo "\n"

 >set echo_style=none
 > echo $echo_style
 > echo -n "test"
 -n test
 > echo "\n"
edit If set, the command-line editor is used. Set by default in interactive shells.
ellipsis If set, the %c'/'%. and %C prompt sequences (see the prompt shell variable) indicate skipped directories with an ellipsis (…) instead of /.
fignore Lists file name suffixes to be ignored by completion.
filec In the tcsh shell, completion is always used and this variable is ignored.
gid The user's real group ID.
group The user's group name.
histchars A string value determining the characters used in history substitution. The first character of its value is used as the history substitution character, replacing the default character ! (exclamation point). The second character of its value replaces the character ^ (caret) in quick substitutions.
histdup Controls handling of duplicate entries in the history list. If set to all only unique history events are entered in the history list. If set to prev and the last history event is the same as the current command, then the current command is not entered in the history. If set to erase and the same event is found in the history list, that old event gets erased and the current one gets inserted. The prev and all options renumber history events so there are no gaps.
histfile The default location in which history -S and history -L look for a history file. If unset, ~/.history is used. histfile is useful when sharing the same home directory between different machines, or when saving separate histories on different terminals. Because only ~/.tcshrc is normally sourced before ~/.history, histfile should be set in ~/.tcshrc instead of ~/.login.
An example:
set histfile = ~/.history 
histlit If set, built-in and editor commands and the savehist mechanism use the literal (unexpanded) form of lines in the history list. See also the toggle-literal-history editor command.
history The first word indicates the number of history events to save. The optional second word indicates the format in which history is printed; if not given, %h\t%T\t%R\n is used. The format sequences are described under prompt. (Note that %R has a variable meaning). Set to 100 by default.
home Initialized to the home directory of the invoker. The file name expansion of ~ refers to this variable.
ignoreeof If set to the empty string or 0 and the input device is a terminal, the end-of-file command (typically generated by the user by typing ^D on an empty line) causes the shell to print 'Use "logout" to leave tcsh.' instead of exiting. This prevents the shell from accidentally being killed. If set to a number n, the shell ignores n - 1 consecutive end-of-files and exits on the nth. If unset, 1 is used. That is, the shell exits on a single ^D.
implicitcd If set, the shell treats a directory name typed as a command as though it were a request to change to that directory. If set to verbose, the change of directory is echoed to the standard output. This behavior is inhibited in non-interactive shell scripts, or for command strings with more than one word. Changing directory takes precedence over executing a like-named command, but it is done after alias substitutions. Tilde and variable expansions work as expected.
inputmode If set to insert or overwrite, puts the editor into that input mode at the beginning of each line.
listflags If set to x, a or A, or any combination thereof (for example, xA), they are used as flags to ls-F, making it act like ls -xF, ls -Fa, ls -FA or a combination (for example, ls -FxA): a shows all files (even if they start with a '.'), A shows all files but '.' and '..', and x sorts across instead of down. If the second word of listflags is set, it is used as the path to ls(1).
listjobs If set, all jobs are listed when a job is suspended. If set to long, the listing is in long format.
listlinks If set, the ls-F built-in command shows the type of file to which each symbolic link points. For an example of its use, see ls-F built-in command for tcsh: List files.
listmax The maximum number of items which the list-choices editor ocmmand will list without asking first.
listmaxrows The maximum number of rows of items which the list-choices editor command will list without asking first.
loginsh Set by the shell if is a login shell. Setting or unsetting it within a shell has no effect. See also shlvl.
logout Set by the shell to normal before a normal logout, automatic before an automatic logout, and hangup if the shell was killed by a hangup signal. See also the autologout shell variable.
mail The names of the files or directories to check for incoming mail, separated by white space, and optionally preceeded by a numeric word. Before each prompt, if 10 minutes have passed since the last check, the shell checks each file and says 'You have new mail.' (or, if mail contains multiple files, 'You have new mail in name.') if the filesize is greater than zero in size and has a modification time greater than its access time.

If you are in a login shell, then no mail file is reported unless it has been modified after the time the shell has started up, in order to prevent redundant notifications. Most login programs will tell you whether or not you have mail when you log in.

If a file specified in mail is a directory, the shell will count each file within that directory as a separate message, and will report 'You have n mails.' or 'You have n mails in name.' as appropriate. This functionality is provided primarily for those systems which store mail in this manner, such as the Andrew Mail System.

If the first word of mail is numeric it is taken as a different mail checking interval, in seconds. Under very rare circumstances, the shell might report 'You have mail.' instead of 'You have new mail.'

matchbeep If set to never, completion never beeps. If set to nomatch, it beeps only when there is no match. If set to ambiguous, it beeps when there are multiple matches. If set to notunique, it beeps when there is one exact and other longer matches. If unset, ambiguous is used.
nobeep If set, beeping is completely disabled.
noclobber If set, restrictions are placed on output redirection to insure that files are not accidentally destroyed and that >> redirections refer to existing files, as described in Input or output.
noglob If set, file name substitution and directory stack substitution are inhibited. This is most useful in shell scripts which do not deal with file names, or after a list of file names has been obtained and further expansions are not desirable.
nokanji If set and the shell supports Kanji (see the version shell variable), it is disabled so that the meta key can be used.
nonomatch If set, a file name substitution or directory stack substitution which does not match any existing files is left untouched instead of causing an error. It is still an error for the substitution to be malformed, that is, echo [ still gives an error.
nostat A list of directories (or glob-patterns which match directories; see File name substitution) that should not be stat(2)ed during a completion operation. This is typically used to exclude directories which take too much time to stat(2), for example /afs.
notify If set, the shell announces job completions asynchronously. The default is to present job completions just before printing a prompt.
owd The old working directory, equivalent to the - (hyphen) used by cd and pushd. See also the cwd and dirstack shell variables.
path A list of directories in which to look for executable commands. A null word specifies the current directory. If there is no path variable then only full path names will be executed. path is set by the shell at startup from the PATH environment variable or, if PATH does not exist, to a system-dependent default something like (/usr/local/bin /usr/bsd /bin /usr/bin .). The shell might put '.' first or last in path or omit it entirely depending on how it was compiled; see the version shell variable. A shell which is given neither the -c nor the -t option hashes the contents of the directories in path after reading ~/.tcshrc and each time path is reset. If you add a new command to a directory in path while the shell is active, you might need to do a rehash for the shell to find it.
printexit- value If set and an interactive program exits with a nonzero status, the shell prints 'Exit status'.
prompt2 The string with which to prompt in while and foreach loops and after lines ending in \ (backslash). The same format sequences can be used as in prompt (note the variable meaning of %R). Set by default to %R? in interactive shells.
prompt3 The string with which to prompt when confirming automatic spelling correction. The same format sequences can be used as in prompt (note the variable meaning of %R). Set by default to CORRECT>%R (y|n|e|a)? in interactive shells.
promptchars If set to a two-character string, the %# formatting sequence in the prompt shell variable is replaced with the first character for normal users and the second character for the superuser.
pushdtohome If set, pushd without arguments does pushd ^, like cd.
pushdsilent If set, pushd and popd do not print the directory stack.
recexact If set, completion completes on an exact match even if a longer match is possible.
recognize_ only_ executables If set, command listing displays only files in the path that are executable.
rmstar If set, the user is prompted before rm * is executed.
rprompt The string to print on the right-hand side of the screen (after the command input) when the prompt is being displayed on the left. It recognises the same formatting characters as prompt. It will automatically disappear and reappear as necessary, to ensure that command input isn't obscured, and will only appear if the prompt, command input, and itself will fit together on the first line. If edit isn't set, then rprompt will be printed after the prompt and before the command input.
savedirs If set, the shell does dirs -S before exiting.
savehist If set, the shell does history -S before exiting. If the first word is set to a number, at most that many lines are saved. (The number must be less than or equal to history.) If the second word is set to merge, the history list is merged with the existing history file instead of replacing it (if there is one) and sorted by time stamp and the most recent events are retained.
An example:
set savehist = ( 15 merge )
sched The format in which the sched built-in command prints scheduled events. If not given, %h\t%T\t%R\n is used. The format sequences are described under prompt; note the variable meaning of %R.
shell The file in which the shell resides. This is used in forking shells to interpret files which have execute bits set, but which are not executable by the system (see Built-in and non-built-in command execution. Initialized to the (system-dependent) home of the shell.
shlvl The number of nested shells. Reset to 1 in login shells. See also loginsh.
status The status returned by the last command. If it terminated abnormally, then 0200 is added to the status. tcsh built-in commands which fail return exit status 1, all other built-in commands return status 0.
tcsh The version number of the shell in the format R.VV.PP, where R is the major release number, VV the current version and PP the patch level.
term The terminal type. Typically set in ~/.login.
tperiod The period, in minutes, between executions of the periodic special alias.
tty The name of the tty, or empty if not attached to one.
uid The user's login name.
user The user's login name.
verbose If set, causes the words of each command to be printed, after history substitution (if any). Set by the –v command line option.
version The version ID stamp. It contains the shell's version number (see tcsh), origin, release date, vendor, operating system and machine (see VENDOR, OSTYPE, and MACHTYPE environment variables) and a comma-separated list of options which were set at compile time. Options which are set by default in the distribution are noted.
The shell is eight bit clean; default.
The shell is not eight bit clean.
The system's multicultural support is used; default for systems with multicultural support.
Login shells execute /etc/csh.login before instead of after /etc/csh.cshrc and ~/.login before instead of after ~/.tcshrc and ~/.history.
'.' is put last in path for security; default.
'.' is omitted from path for security.
vi-style editing is the default instead of emacs.
Login shells drop DTR when exiting.
bye is a synomym for logout and log is an alternate name for watchlog.
autologout is enabled; default.
Kanji is used and the ISO character set is ignored, unless the nokanji shell variable is set.
The system's malloc is used.
The #!<program> <args> convention is emulated when executing shell scripts.
The newgrp built-in is available.
The shell attempts to set the REMOTEHOST environment variable.
The shell verifies your password or password phrase with the Kerberos server if local authentication fails. The afsuser shell variable or the AFSUSER environment variable will override your local username if set.
An administrator can enter additional strings to indicate differences in the local version.
visiblebell If set, a screen flash is used instead of the audible bell. See nobeep. (Currently not implemented.)
watch A list of user/terminal pairs to watch for logins and logouts. If either the user is any all terminals are watched for the given user and vice versa. Setting watch to (any any) watches all users and terminals. For example,
set watch = (george ttyd 1 any console $user any)
reports activity of the user george on ttyd1, any user on the console, and oneself (or a trespasser) on any terminal.
Logins and logouts are checked every 10 minutes by default, but the first word of watch can be set to a number to check every so many minutes. For example,
set watch = (1 any any)
reports any login/logout once every minute. For the impatient, the log built-in command triggers a watch report at any time. All current logins are reported (as with the log built-in) when watch is first set.

The who shell variable controls the format of watch reports.

who The format string for watch messages. The following sequences are replaced by the given information:
The name of the user who logged in/out.
The observed action, i.e., 'logged on'. 'logged off', or 'replaced olduser on'.
The terminal (tty) on which the user logged in/out.
The full hostname of the remote host, or 'local' if the login/logout was from the local host.
The hostname of the remote host up to the first '.' (period). The full name is printed if it is an IP address or an X Window System display.
%M and %m are available only on systems that store the remote hostname in /etc/utmp. If unset, %n has %a %l from %m. is used, or %n has %a %l. on systems which do not store the remote hostname.
wordchars A list of non-alphanumeric characters to be considered part of a word by the forward-word, backward word, etc. editor commands. If unset, *?_-.[] ~= is used.

tcsh shell variables not described in the Table 2 are described as follows:

The string which is printed before reading each command from the terminal. prompt can include any of the following formatting sequences, which are replaced by the given information:
The current working directory.
The current working directory, but with one's home directory represented by ~ and other users' home directories represented by ~user as per file name substitution. ~user substitution happens only if the shell has already used ~user in a path name in the current session.
%c[[0]n], %.[[0]n]
The trailing component of the current working directory, or n trailing components if a digit n is given. If n begins with 0, the number of skipped components precede the trailing components in the format /trailing. If the ellipsis shell variable is set, skipped components are represented by an ellipsis so the whole becomes …trailing. ~ substitution is done as in %~~ , but the ~ component is ignored when counting trailing components.
Like %c, but without ^ substitution.
%h, %!, !
The current history event number.
The full hostname.
The hostname up to the first '.' (period).
%S (%s)
Start (stop) standout mode.
%B (%b)
Start (stop) boldfacing mode.
%U (%u)
Start (stop) underline mode.
%t, %@
The time of day in 12–hour AM/PM format.
Like %t, but in 24–hour format (but see the ampm shell variable).
The precise time of day in 12–hour AM/PM format, with seconds.
Like %p, but in 24–hour format (but see the ampm shell variable).
c is parsed as in bindkey.
c is parsed as in bindkey.
A single %.
The user name.
The weekday in 'Day' format.
The day in 'dd' format.
The month in 'Mon' format.
The month in 'mm' format.
The year in 'yy' format.
The year in 'yyyy' format.
The tcsh shell's tty.
Clears from the end of the prompt to end of the display or the end of the line.
Expands the shell or environment variable name immediately after the $.
> (or the first character of the promptchars shell variable) for normal users, # (or the second character of promptchars) for the superuser.
Includes string as a literal escape sequence. It should be used only to change terminal attributes and should not move the cursor location. This cannot be the last sequence in prompt.
The return code of the command executed just before the prompt.
In prompt2, the status of the parser. In prompt3, the corrected string. In history, the history string.
The bold, standout and underline sequences are often used to distinguish a superuser shell. For example,
>set prompt = "%m [%h] %B[%@%b [%/] you rang?"
tut [37] [2:54] [/usr/accts/sys] you rang? _
Set by default to %# in interactive shells.
Can be set to several different values to control symbolic link ('symlink') resolution:
  • If set to chase, whenever the current directory changes to a directory containing a symbolic link, it is expanded to the real name of the directory to which the link points. This does not work for the user's home directory.
  • If set to ignore, the shell tries to construct a current directory relative to the current directory before the link was crossed. This means that cding through a symbolic link and then cd..'ing returns one to the original directory. This only affects built-in commands and file name completion.
  • If set to expand, the shell tries to fix symbolic links by actually expanding arguments which look like path names. This affects any command, not just built-ins. Unfortunately, this does not work for hard-to-recognize file names, such as those embedded in command options. Expansion can be prevented by quoting. While this setting is typically the most convenient, it is sometimes misleading and sometimes confusing when it fails to recognize an argument which should be expanded. A compromise is to use ignore and use the editor command normalize-path (bound by default to ^X-n) when necessary.
Some examples are in order. First, let's set up some play directories:
        > cd /tmp
        > mkdir from from/src to
        > ln -s from/src to/dist 
Here's the behavior with symlinks unset,
        > cd /tmp/to/dist; echo $cwd
        > cd ..; echo $cwd
here's the behavior with symlinks set to chase,
        > cd /tmp/to/dst; echo $cwd
        > cd ..; echo $cwd
here's the behavior with symlinks set to ignore,
        > cd /tmp/to/dist; echo $cwd
        > cd ..; echo $cwd
and here's the behavior with symlinks set to expand.
        > cd /tmp/to/dist; echo $cwd
        > cd ..; echo $cwd
        > cd /tmp/to/dist; echo $cwd
        > cd ".."; echo $cwd
        > /bin/echo ..
        > /bin/echo ".."
expand expansion:
  1. works just like ignore for built-ins like cd,
  2. is prevented by quoting, and
  3. happens before file names are passed to non-built-in commands.
If set to a number, then the time built-in command executes automatically after each command which takes more than that many CPU seconds. If there is a second word, it is used as a format string for the output of the time built-in. The following sequences can be used in the format string:
The time the process spent in user mode in cpu seconds.
The time the process spent in kernel mode in cpu seconds.
The elapsed (wall clock) time in seconds.
The CPU percentage computed as (%U + %S) / %E.
The number of times the process was swapped.
The average amount in (shared) text space used in Kbytes.
The average amount in (unshared) data/stack space used in Kbytes.
The total space used (%X + %D) in Kbytes.
The maximum memory the process had in use at any time in Kbytes.
The number of major page faults (page needed to be brought from disk).
The number of minor page faults.
The number of input operations.
The number of output operations.
The number of socket messages received.
The number of socket messages sent.
The number of signals received.
The number of voluntary context switches (waits).
The number of involuntary context switches.
Only the first four sequences are supported on systems without BSD resource limit functions. The default time format is
Uu   %Ss %E %P %X+%Dk %I+%Oio   %Fpf+%Ww
for systems that support resource usage reporting.

The following table contains a list of tcsh environment variables.

Table 3. tcsh environment variables
Environment variable Purpose
COLUMNS A list of directories in which cd should search for subdirectories if they aren't found in the current directory.
DISPLAY Used by X Window System. If set, the shell does not set AUTOLOGOUT.
EDITOR The path name to a default editor. See also the VISUAL environment variable and the run-fg-editor editor command.
GROUP Equivalent to the group shell variable.
HOME Equivalent to the HOME shell variable.
HOST Initialized to the name of the machine of the machine on which the shell is running, as determined by the gethostname system call.
HOSTTYPE Initialized to the type of the machine on which the shell is running, as determined at compile time. This variable is obsolete and will be removed in a future version.
HPATH A colon-separated list of directories in which the run-help editor command looks for a command documentation.
LANG Gives the preferred character environment. See National language system report.
LC_CTYPE If set, only CTYPE character handling is changed. See National language system report.
LINES The number of lines in the terminal. See Managing terminals.
MACHTYPE The machine type (microprocessor class or machine model), as determined at compile time.
NOREBIND If set, printable characters are not rebound to SELF-INSERT-COMMAND. After a user sets NOREBIND, a new shell must be started. See National language system report.
OSTYPE The operating system, as determined at compile time.
PATH A colon-separated list of directories in which to look for executables. Equivalent to the path shell variable, but in a different format.
PWD Equivalent to the cwd shell variable, but not synchronized to it; updated only after an actual directory change.
REMOTE- HOST The host from which the user has logged in remotely, if this is the case and the shell is able to determine it. (The z/OS tcsh shell is not currently compiled with REMOTEHOST defined; see the version shell variable.)
SHLVL Equivalent to the shlvl shell variable.
TERM Equivalent to the term shell varialbe.
USER Equivalent to the user shell variable.
VENDOR The vendor, as determined at compile time.
VISUAL The path name to a default full-screen editor. See the editor environment variable and the run-fg-editor editor command.

Using tcsh shell variables to control automatic conversion

When the tcsh shell is redirecting stdin, stdout, or stderr, it will default to no automatic conversion of tagged files, and no tagging of files created by the redirection. The following tcsh shell variables will override this behavior:
Redirected stdin will override the file's TXTFLAG, treating it as if it were tagged as:

TXTFLAG = ON, CCSID = existing file tag CCSID

This has no effect if CCSID = 0.

Redirected stdin will override the file's TXTFLAG, treating it as if it were tagged as:

TXTFLAG = OFF, CCSID = existing file tag CCSID

This effectively disables automatic conversion.

Redirected stdout is tagged as:

TXTFLAG = ON, CCSID = program CCSID at the time of the first write (if not already tagged)

Redirected stdout is tagged as:

TXTFLAG = OFF, CCSID = program CCSID at the time of the first write (if not already tagged)

Redirected stderr is tagged as:

TXTFLAG = ON, CCSID = program CCSID at the time of the first write (if not already tagged)

Redirected stderr is tagged as:

TXTFLAG = OFF, CCSID = program CCSID at the time of the first write (if not already tagged)

The automatic conversion shell variable can be specified for one command, or for multiple commands within a tcsh shell session or shell script. If the variable is set in a user's .tcshrc file, then it will affect child shells, that is, nested shell scripts.
Note: Because the standard tcsh shell execution performs redirection before variable assignment, the syntax for specifying the shell variable for one command is set var=value. For example:
(set _TAG_REDIR_OUT=TXT; command >file)

Start of changeYou can also use these shell variables for commands in a pipeline. For example, they can be used to tag the standard output of each command that is writing to a pipeline or to tag the standard input of each command that is reading from a pipeline.End of change

tcsh files

Read first by every shell.
Read by login shells after /etc/csh.cshrc.
Read by every shell after /etc/csh.cshrc or its equivalent.
Read by login shells after ~/.tcshrc if savehist is set. See also histfile.
The shell reads ~/.login after ~/.tcshrc and ~/.history. See the version shell variable.
Read by login shells after ~/.login if savedirs is set. See also dirsfile.
Read by login shells at logout.
Used to interpret shell scripts not starting with a #.
Temporary file for < <.

tcsh shell: problems and limitations

Some limitations of the tcsh shell are:
  • Words can be no longer than 1024 characters.
  • The system limits argument lists to 10240 characters.
  • The number of arguments to a command which involves file name expansion is limited to 1/6th the number of characters allowed in an argument list.
  • Command substitutions can substitute no more characters than are allowed in an argument list.
  • To detect looping, the shell restricts the number of alias substitutions on a single line to 20.

When a suspended command is restarted, the tcsh shell prints the directory it started in if this is different from the current directory. This can be misleading (that is, wrong) as the job might have changed directories internally.

Shell built-in functions are not stoppable/restartable. Command sequences of the form 'a ; b ; c' are also not handled gracefully when stopping is attempted. If you suspend 'b', the tcsh shell will then immediately execute 'c'. This is especially noticeable if this expansion results from an alias. It suffices to place the sequence of commands in ()'s to force it to a subshell, for example, ( a ; b ; c ).

Control over tty output after processes are started is primitive. In a virtual terminal interface much more interesting things could be done with output control.

Alias substitution is most often used to clumsily simulate shell procedures; shell procedures should be provided instead of aliases.

Commands within loops are not placed in the history list. Control structures should be parsed instead of being recognized as built-in commands. This would allow control commands to be placed anywhere, to be combined with |, and to be used with & and ; (semicolon) metasyntax.

foreach does not ignore here-documents when looking for its end.

It should be possible to use the : (colon) modifiers on the output of command substitutions.

The screen update for lines longer than the screen width is very poor if the terminal cannot move the cursor up (terminal type 'dumb').

It is not necessary for HPATH and NOREBIND to be environment variables.

Glob-patterns which do not use '?', '*' or '[]' or which use '{}' or '~' are not negated correctly.

The single-command form of if does output redirection even if the expression is false and the command is not executed.

ls-F includes file identification characters when sorting file names and does not handle control characters in file names well. It cannot be interrupted.

The visiblebell shell variable is currently not implemented.

In file name and programmed completion, the 'C' completion rule word list type does not correctly select completion from the given directory.

There are three locales (code pages) which the tcsh shell will not correctly support: IBM-1388 (Chinese), IBM-933 (Korean) and IBM-937 (Traditional Chinese).

If you want to help maintain and test tcsh, send mail to with the text 'subscribe tcsh '.

Related information

: (colon), @ (at), alias, bg, break, cd, continue, echo, eval, exec, exit, fg, history, jobs, kill, newgrp, nice, nohup, printenv, set, shift, stop, suspend, time, umask, unalias, unset, wait