tcsh - Invoke a C shell
Format
tcsh [-bcdeFfimnqstvVxX]
Description
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.
The names of the system login and logout files vary from system to system for compatibility with different csh variants; see tcsh files.
Options
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.
- -b
- 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.
- -c
- 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.
- -d
- Loads the directory stack from ~/.cshdirs whether or not it is a login shell.
- -e
- Terminates shell if any invoked command terminates abnormally or yields a nonzero exit status.
- -i
- 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.
- -l
- Invokes a login shell. Only applicable if -l is the only option
specified. Note: -l is a lowercase L not an uppercase i.
- -m
- Loads ~/.tcshrc even if it does not belong to the effective user.
- -n
- Parses commands but does not execute them. This aids in debugging shell scripts.
- -q
- Accepts SIGQUIT and behaves when it is used under a debugger. Job control is disabled.
- -s
- Take command input from the standard input.
- -t
- 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.
- -v
- Sets the verbose shell variable so command input is echoed after history substitution.
- -V
- Sets the verbose shell variable even before executing ~/.tcshrc.
- -x
- Sets the echo shell variable so commands are echoed immediately before execution.
- -X
- 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
The command-line editor is described. We then discuss Completion and Listing and Spelling Correction. They are two sets of functionality that are implemented as editor commands. 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 by 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.
- down
- down-history
- up
- up-history
- left
- backward-char
- right
- forward-char
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. (To speed up typing and to provide a visual indicator of successful completion, the
terminal /
(forward slash); completion adds a /
to the end of
completed directories and a space to the end of other completed words. The
addsuffix shell variable can be unset to prevent this action.) If no match is
found (for example, /usr/lost+found does not 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 is not 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. Those leftover characters 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.
> ls /usr/l[^D]
lbin/ lib/ local/ lost+found/
> ls /usr/l
> 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.
> ls ~k[^D]
kahn kas kellogg
> ls ~ke[tab]
> ls ~kellogg/
or
> 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.
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 in 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.
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.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. nostat
is evident when using the listflags
variable. For example:
>set listflags=x>
ls-F /u/pluto
Dir1/exe1*
>set nostat=(/u/pluto/)
>ls-F /u/pluto
Dir1exe1
>
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.
> 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, ato 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 that are bound to letters by default are bound to both lowercase and uppercase letters for convenience.
- complete-word
- Completes a word as described in Completion and listing.
- complete-word-back
- Like complete-word-fwd, but steps up from the end of the list.
- complete-word-fwd
- 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.
- complete-word-raw
- Like complete-word, but ignores user-defined completions.
- copy-prev-word
- Copies the previous word in the current line into the input buffer. See also insert-last-word.
- dabbrev-expand
- 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.
- down-history
- Like up-history, but steps down, stopping at the original input line.
- end-of-file
- 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.
- expand-glob(^X-*)
- Expands the glob-pattern to the left of the cursor. For example:
would expand to>ls test*[^X-*]
if those were the only two files in your directory that begin with 'test'. See File name substitution.>ls test1.c test2.c
- 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:
- ^W
- 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.
- ^G
- If the previous search was successful, aborts the entire search. If not, goes back to the last successful search.
- escape
- Ends the search, leaving the current line in the input buffer.
- i-search-fwd
- 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.help, command.1, command.6, command.8 or command, which should be in one of the directories listed in the HPATH environment 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)
- Beeps.
- 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 action might make complex quoting tasks easier but can cause syntax errors in csh (or tcsh)
scripts.
Substitutions
The tcsh shell performs various transformations on input in the order in which they occur. The topic covers data structures and the commands and variables that 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.
- n
- A number, referring to a particular event.
- -n
- 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, which is equivalent to
-1
. - s
- The most recent event whose first word begins with the string s.
- ?s?
- The most recent event which contains the string s. The second ? can be omitted if it is immediately followed by a newline.
9 8:30 nroff -man wumpus.man
10 8:31 cp wumpus.man wumpus.man old
11 8:36 vi wumpus.man
12 8:37 diff wumpus.man.old wumpus.man
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
.
- 0
- The first command word
- n
- The nth argument
- ^
- The first argument, equivalent to
1
- $
- The last argument
- %
- The word matched by an ?s? search
- x-y
- A range of words
- -y
- Equivalent to 0-y
- *
- Equivalent to
^-$
, but returns nothing if the event contains only 1 word - x*
- Equivalent to x-$
- x-
- Equivalent to x*, but omitting the last word ($)
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 !*.
:
(colon): - h
- Remove a trailing path name component, leaving the head.
- t
- Remove all leading path name components, leaving the tail.
- r
- Remove a file name extension .xxx, leaving the root name.
- e
- Remove all but the extension
- u
- Uppercase the first lowercase letter.
- l
- Lowercase the first uppercase letter.
- s/l/r
- 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
- g
- Apply the following modifier once to each word.
- a
- 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.
- p
- Print the new command line but do not execute it.
- q
- Quote the substituted words, preventing further substitutions.
- x
- Like q, but break into words at blanks, tabs and newlines.
For example, the diff command might have been written as diff wumpus.man.old !#^: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 !.
% mv wumpus.man /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 $.- 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
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.
- $name[selector]
- ${name[selector]}
- 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.
- $0
- Substitutes the name of the file from which command input is being read. An error occurs if the name is not known.
- $number
- ${number}
- Equivalent to $argv[number].
- $*
- Equivalent to $argv, which is equivalent to $argv[*].
:
(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. - $?name
- ${?name}
- Substitutes the string
1
if name is set,0
if it is not. - $0
- Substitutes the name of the file from which command input is being read. An error occurs if the name is not known.
- $?0
- Substitutes
1
if the current input file name is known,0
if it is not. Always0
in interactive shells. - $#name or ${#name}
- Substitutes the number of words in name.
- $#
- Equivalent to '$#argv'.
- $%name
- ${%name}
- Substitutes the number of characters in name.
- $%number
- ${%number}
- 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 remaining substitutions are applied selectively to the arguments of tcsh built-in commands. This means that portions of expressions that are not evaluated are not subjected to these expansions. For commands that 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 that are separated by - matches any character lexically between the two.
Some glob-patterns can be negated: The sequence [^...] matches any single character that is not specified by the characters and ranges of characters in the braces.
> echo *
bang crash crunch ouch
> echo ^cr*
bang ouch
Glob-patterns which do not use '?', '*', or'[]'
or which use '{}' or '^' are not negated correctly.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 that 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 that is 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. 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.
=-
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
/usr/spool/uucp
> echo =0/calendar
/usr/bin/calendar
> echo =-
/usr/accts/sys
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, 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.
(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
For a table that lists the standard input/output syntax for the tcsh shell, see the tcsh command in z/OS UNIX System Services Command Reference.
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.
Features
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 that 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.)
Expressions
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
|| && | ^ & == != =~ !~ <= >=
< > << >> + - * / % ! ~ ( )
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. No
two components of an expression can appear in the same word; except
when adjacent to components of expressions that are syntactically
significant to the parser ('$' '|' '<' '>' '(' ')') they must 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 must be executed outside
of an expression and the status shell variable examined.
File inquiry operators
- ac
- An extended ACL of type c exists. Character c represents
the type of ACL:
- a
- Access ACL
- d
- Directory default ACL
- f
- File default ACL
- r
- Read access (as determined by security product and effective IDs)
- w
- Write access (as determined by security product and effective IDs)
- x
- Execute access (as determined by security product and effective IDs)
- X
- 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.)
- e
- Existence
- Ea
- File has the APF extended attribute
- Ep
- File has the program
- Es
- File has the shared address space extended attribute
- El
- File has the shared library extended attribute
- o
- Ownership
- x
- Zero size
- s
- Nonzero size
- f
- Plain file
- d
- Directory
- l
- Symbolic link
- b
- Block special file
- c
- Character special file
- p
- Named pipe (fifo)
- S
- Socket special file
- u
- Set-user ID bit is set
- g
- Set-group-ID bit is set
- k
- Sticky bit is set
- t
- t file_descriptor (which must be a digit) is an open file descriptor for a terminal device
- L
- Applies subsequent operators in a multiple-operator test to a symbolic link instead of to the file to which the link points
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 true 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.
0
or
1
. They have the same format as before where op can be one of the
following choices: - A
- Last file access time, as the number of seconds since epoch.
- A:
- Like
A
, but in time stamp format, that is, 'Fri May 14 16:36:10 1993'. - M
- Last file modification time.
- M:
- Like
M
, but in time stamp format. - C
- Last inode modification time.
- C:
- Like
C
, but in time stamp format. - D
- Device number.
- I
- Inode number.
- F
- Composite file identifier, in the form
device : inode
. - L
- The name of the file pointed to by a symbolic link.
- N
- Number of (hard) links.
- P
- Permissions, in octal, without leading zeros.
- P:
- Like P, with leading zeros.
- 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, and0
if by neither. - P mode:
- Like
P mode
, with leading zeros. - U
- Numeric user ID.
- U:
- Username, or the numeric user ID if the username is unknown.
- G
- Numeric group ID.
- G:
- Group name, or the numeric group ID if the group name is unknown.
- Z
- Size in bytes.
- m file
- Returns the security label of the file if one exists. Otherwise, returns false.
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.
if ( -T file == IBM-1047 ) #True if tagged as IBM-1047 text
if ( -B file ) #True if tagged as binary
Jobs
[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 that 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.
- The sched built-in command puts commands in a scheduled-event list, to be executed by the shell at a given time.
- The beepcmd, cwdcmd, periodic and precmd special aliases can be set, respectively, to execute commands when the shell wants to ring the bell, when the working directory changes, every t-period minutes and before each prompt.
- The autologout shell variable can be set to log out of the shell after a given number of minutes of inactivity.
- The mail shell variable can be set to check for new mail periodically.
- The printexitvalue shell variable can be set to print the exit status of commands which exit with a status other than zero.
- The rmstar shell variable can be set to ask the user, when rm * is typed, if that is really what was meant.
- The time shell variable can be set to execute the time built-in command after the completion of any process that takes more than a given number of CPU seconds.
- The watch and who shell variables can be set to report when selected users log in or out, and the log built-in command reports on those users at any time.
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).
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 that 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.
@ (at) | filetest | notify | source |
% | glob | onintr | telltc |
alloc | hashstat | popd | uncomplete |
bindkey | hup | pushd | unhash |
builtins | limit | rehash | unlimit |
bye | log | repeat | unsetenv |
chdir | login | sched | watchlog |
complete | logout | setenv | where |
dirs | ls-F | settc | which |
echotc | notify | setty |
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.
: (colon) | continue | fg | nice | stop | unset |
alias | echo | history | nohup | suspend | wait |
bg | eval | jobs | printenv | time | writedown |
break | exec | kill | set | umask | |
cd | exit | newgrp | shift | unalias |
- beepcmd
- cwdcmd
- periodic
- precmd
- shell
- beepcmd
- Runs when the shell wants to ring the terminal bell.
- cwdcmd
- 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
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"'
This will put the host name and working directory on the title bar but only the host name in the icon manager menu. Putting a cd, pushd or popd in cwdcmd might cause an infinite loop.> alias cwdcmd 'echo -n "^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"'
- periodic
- 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
then the checknews program runs every 30 minutes. If periodic is set but tperiod is unset or set to 0, periodic behaves like precmd.> set tperiod = 30 > alias periodic checknews
- precmd
- Runs just before each prompt is printed. For example, if one does
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.> alias precmd date
- shell
- Specifies the interpreter for executable scripts that 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).
Programming constructs
Construct | Action |
---|---|
breaksw | Causes a break from a switch, resuming after the endsw. |
case label | A label in a switch. See the switch built-in description. |
continue | Continues execution of the nearest enclosing while or foreach. The rest of the commands on the current line are executed. |
default | Labels the default case in a switch statement. It should come after all case labels. |
else
end endif endsw |
See the description of the foreach, if, switch, and while statements that follow. |
goto word | With goto, word is file name and command substituted to yield a string of the form label. The tcsh shell rewinds its input as much as possible, searches for a line of the form label, possible preceded by blanks or tabs, and continues execution after that line. |
foreach
... end |
Successively sets the variable name to each member of wordlist and executes the sequence of commands between this command and the matching end. (Both foreach and end must appear alone on separate lines.) The built-in command continue can be used to continue the loop prematurely and the built-in command break to terminate it prematurely. When this command is read from the terminal, the loop is read once prompting with foreach? (or prompt2) before any statements in the loop are executed. If you make a mistake typing in a loop at the terminal you can rub it out. |
if (expr) then
... else if (expr2) then ... else ... endif |
If the specified expr is true then the commands to the first else are executed; otherwise if expr2 is true then the commands to the second else are executed. Any number of else-if pairs are possible; only one endif is needed. The else part is optional. (The words else and endif must appear at the beginning of input lines; the if must appear alone on its input line or after an else.) |
switch (string)
case str1: ... breaksw ... default ... breaksw endsw |
Each case label is successively matched, against the specified string which is first command and file name expanded. The file metacharacters *, ? and [...] can be used in the case labels, which are variable expanded. If none of the labels match before a default label is found, then the execution begins after the default label. Each case label and the default label must appear at the beginning of a line. The command breaksw causes execution to continue after the endsw. Otherwise control might fall through case labels and default labels as in C. If no label matches and there is no default, execution continues after the endsw. |
while (expr)
... end |
Executes the commands between the while and the matching end while expr (expression) evaluates nonzero. while and end must appear alone on their input lines. break and continue can be used to terminate or continue the loop prematurely. If the input is a terminal, the user is prompted the first time through the loop as with foreach. |
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.
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 overrides 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 that 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:
|
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:
The
following is an example of this variable's use:
|
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:
|
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 that is 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 that the list-choices editor command will list without asking first. |
listmaxrows | The maximum number of rows of items that 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. |
The names of the files or directories to check for incoming mail,
separated by white space, and optionally preceded 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 that 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 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 | Beeping is completely disabled. |
noclobber | Restrictions are placed on output redirection to ensure that files are not accidentally destroyed and that >> redirections refer to existing files, as described in Input or output. |
noglob | File name substitution and directory stack substitution are inhibited. This option is most useful in shell scripts that do not deal with file names, or after a list of file names has been obtained and further expansions are not wanted. |
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 | A file name substitution or directory stack substitution that 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 that 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 | 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 | pushd without arguments does pushd ^, like cd. |
pushdsilent | pushd and popd do not print the directory stack. |
recexact | Completion completes on an exact match even if a longer match is possible. |
recognize_ only_ executables | Command listing displays only files in the path that are executable. |
rmstar | The user is prompted before rm * is executed. |
rprompt | The string to print on the right side of the screen (after the command input) when the prompt is being displayed on the left. It recognizes 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 | The shell does dirs -S before exiting. |
savehist | 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:
|
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 | The words of each command are 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.
|
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,
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,
reports any logins or logouts 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:
|
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 1 are described as follows:
- prompt
- 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. - %C
- Like %c, but without ^ substitution.
- %h, %!, !
- The current history event number.
- %M
- The full host name.
- %m
- The host name 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.
- %T
- Like %t, but in 24-hour format (but see the ampm shell variable).
- %p
- The precise time of day in 12-hour AM/PM format, with seconds.
- %P
- Like %p, but in 24-hour format (but see the ampm shell variable).
- \c
- c is parsed as in bindkey.
- ^c
- c is parsed as in bindkey.
- %%
- A single %.
- %n
- The user name.
- %d
- The weekday in
Day
format. - %D
- The day in
dd
format. - %w
- The month in
Mon
format. - %W
- The month in
mm
format. - %y
- The year in
yy
format. - %Y
- The year in
yyyy
format. - %l
- The tcsh shell's tty.
- %L
- 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.
- %{string%}
- 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.
- %R
- 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 by default to %# in interactive shells.>set prompt = "%m [%h] %B[%@%b [%/] you rang?" tut [37] [2:54] [/usr/accts/sys] you rang? _
- symlinks
- Can be set to several different values to control symbolic
link 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.
Here's the behavior with symbolic links unset,> cd /tmp > mkdir from from/src to > ln -s from/src to/dist
here's the behavior with symbolic links set to chase,> cd /tmp/to/dist; echo $cwd /tmp/to/dist > cd ..; echo $cwd /tmp/from
here's the behavior with symbolic links set to ignore,> cd /tmp/to/dst; echo $cwd /tmp/from/src > cd ..; echo $cwd /tmp/from
and here's the behavior with symbolic links set to expand.> cd /tmp/to/dist; echo $cwd /tmp/to/dst > cd ..; echo $cwd /tmp/to
expand expansion works just like ignore for built-ins like cd, is prevented by quoting, and happens before file names are passed to non-built-in commands.> cd /tmp/to/dist; echo $cwd /tmp/to/dst > cd ..; echo $cwd /tmp/to > cd /tmp/to/dist; echo $cwd /tmp/to/dst > cd ".."; echo $cwd /tmp/from > /bin/echo .. /tmp/to > /bin/echo ".." ..
- time
- If
set to a number, then the time built-in
command executes automatically after each command that 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:
- %U
- The time the process that is spent in user mode in CPU seconds.
- %S
- The time the process that is spent in kernel mode in CPU seconds.
- %E
- The elapsed (wall clock) time in seconds.
- %P
- The CPU percentage that is computed as (%U + %S) / %E.
- %W
- The number of times the process was swapped.
- %X
- The average amount in (shared) text space that is used in Kbytes.
- %D
- The average amount in (unshared) data/stack space that is used in Kbytes.
- %K
- The total space used (%X + %D) in Kbytes.
- %M
- The maximum memory the process had in use at any time in Kbytes.
- %F
- The number of major page faults (page that is needed to be brought from disk).
- %R
- The number of minor page faults.
- %I
- The number of input operations.
- %O
- The number of output operations.
- %r
- The number of socket messages received.
- %s
- The number of socket messages sent.
- %k
- The number of signals received.
- %w
- The number of voluntary context switches (waits).
- %c
- The number of involuntary context switches.
for systems that support resource usage reporting.Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww
Table 2 contains a list of 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
- _TAG_REDIR_IN=TXT
- 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.
- _TAG_REDIR_IN=BIN
- 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.
- _TAG_REDIR_OUT=TXT
- Redirected
stdout is tagged as:
TXTFLAG = ON, CCSID = program CCSID at the time of the first write (if not already tagged)
- _TAG_REDIR_OUT=BIN
- Redirected stdout is tagged
as:
TXTFLAG = OFF, CCSID = program CCSID at the time of the first write (if not already tagged)
- _TAG_REDIR_ERR=TXT
- Redirected stderr is tagged
as:
TXTFLAG = ON, CCSID = program CCSID at the time of the first write (if not already tagged)
- _TAG_REDIR_ERR=BIN
- Redirected stderr is tagged
as:
TXTFLAG = OFF, CCSID = program CCSID at the time of the first write (if not already tagged)
set var=value
. For
example: (set _TAG_REDIR_OUT=TXT; command >file)
You 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.
tcsh files
- /etc/csh.cshrc
- Read first by every shell.
- /etc/csh.login
- Read by login shells after /etc/csh.cshrc.
- ~/.tcshrc
- Read by every shell after /etc/csh.cshrc or its equivalent.
- ~/.history
- Read by login shells after ~/.tcshrc if savehist is set. See also histfile.
- ~/.login
- The shell reads ~/.login after ~/.tcshrc and ~/.history. See the version shell variable.
- ~/.cshdirs
- Read by login shells after ~/.login if savedirs is set. See also dirsfile.
- ~/.logout
- Read by login shells at logout.
- /bin/sh
- Used to interpret shell scripts not starting with a #.
- /tmp/sh*
- Temporary file for < <.
tcsh shell: problems and limitations
- 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 that 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, more options are available for 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 that are longer than the screen width is very poor if the terminal
cannot move up the cursor up (terminal type 'dumb'
).
It is not necessary for HPATH and NOREBIND to be environment variables.
Glob-patterns that 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 file names are being sorted 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 listserv@mx.gw.com 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