TCSH(1)

okay so this is TCSH(1) from the General Commands Manual, and bestie there is a LOT to get through, so hydrate first ๐Ÿ“๐Ÿ’ง

๐ŸŒธ NAME ๐ŸŒธ

tcsh โ€” C shell with file name completion and command line editing โœจ

โœจ SYNOPSIS โœจ

tcsh [-bcdefFimnqstvVxX] [-Dname[=value]] [arg] ...
tcsh -l

๐Ÿ’– DESCRIPTION ๐Ÿ’–

okay so tcsh is an enhanced but completely compatible version of the Berkeley UNIX C shell, csh(1). like, fully compatible, no cap. It's a command language interpreter that you can use as an interactive login shell and as a shell script command processor โ€” both jobs, main character energy ๐Ÿ‘‘

It comes with:

  • a command-line editor โ€” see โ€œThe command-line editor (+)โ€
  • programmable word completion โ€” see โ€œCompletion and listing (+)โ€
  • spelling correction โ€” see โ€œSpelling correction (+)โ€
  • a history mechanism โ€” see โ€œHistory substitutionโ€
  • job control โ€” see โ€œJobsโ€
  • and a C-like syntax, because of course ๐Ÿ’…

The โ€œNEW FEATURES (+)โ€ section is where the major glow-ups of tcsh over csh(1) live.

Quick legend so you're never confused, iykyk:

  • features of tcsh that you won't find in most csh(1) implementations (specifically, the 4.4BSD csh(1)) are labeled with โ€˜(+)โ€™
  • features that are in csh(1) but usually go undocumented are labeled with โ€˜(u)โ€™

๐ŸŽ€ Argument list processing ๐ŸŽ€

so if the first argument (argument 0) to the shell is - then it's a login shell. simple. A login shell can also happen if you invoke the shell with the -l flag as the only argument.

The rest of the flag arguments get interpreted like this, bestie:

  • -b โ€” Forces a โ€œbreakโ€ from option processing, so any further shell arguments get treated as non-option arguments. The remaining arguments will not be interpreted as shell options. This is how you pass options to a shell script without confusion or possible subterfuge ๐Ÿ•ต๏ธ. Heads up: the shell will not run a set-user ID script without this option.
  • -c โ€” Commands are read from the following argument (which must be present, and must be a single argument), stored in the command shell variable for reference, and executed. Any remaining arguments get placed in the argv shell variable.
  • -d โ€” The shell loads the directory stack from ~/.cshdirs as described under โ€œStartup and shutdownโ€, whether or not it's a login shell. (+)
  • -Dname[=value] โ€” Sets the environment variable name to value. (Domain/OS only) (+)
  • -e โ€” The shell exits if any invoked command terminates abnormally or yields a non-zero exit status. it said what it said ๐Ÿ’€
  • -f โ€” The shell does not load any resource or startup files, or perform any command hashing, and thus starts faster. speedrun mode โšก
  • -F โ€” The shell uses fork(2) instead of vfork(2) to spawn processes. (+)
  • -i โ€” The shell is interactive 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 โ€” The shell is a login shell. Only applicable if -l is the only flag specified.
  • -m โ€” The shell loads ~/.tcshrc even if it does not belong to the effective user. Newer versions of su(1) can pass -m to the shell. (+)
  • -n โ€” The shell parses commands but does not execute them. Great for debugging shell scripts ๐Ÿ›
  • -q โ€” The shell accepts SIGQUIT (see โ€œSignal handlingโ€) and behaves when it is used under a debugger. Job control is disabled. (u)
  • -s โ€” Command input is taken from the standard input.
  • -t โ€” The shell reads and executes a single line of input. A \ may be used to escape the newline at the end of this line and continue onto another line.
  • -v โ€” Sets the verbose shell variable, so that command input is echoed after history substitution.
  • -x โ€” Sets the echo shell variable, so that commands are echoed immediately before execution.
  • -V โ€” Sets the verbose shell variable even before executing ~/.tcshrc.
  • -X โ€” Is to -x as -V is to -v. yes that's the whole description, it's giving parallel structure ๐Ÿฆ‹
  • --help โ€” Print a help message on the standard output and exit. (+)
  • --version โ€” Print the version/platform/compilation options on the standard output and exit. This information is also contained in the version shell variable. (+)

After all that flag processing, if arguments remain but none of the -c, -i, -s, or -t options 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.

Now, because many systems use either the standard version 6 or version 7 shells whose shell scripts are not compatible with this shell, the shell uses such a โ€œstandardโ€ shell to execute a script whose first character is not a # โ€” like, that does not start with a comment.

Remaining arguments are placed in the argv shell variable. periodt.


๐Ÿฆ‹ Startup and shutdown ๐Ÿฆ‹

A login shell begins by executing commands from the system files /etc/csh.cshrc and /etc/csh.login. Then it executes commands from files in the user's home directory, in this order bestie:

  1. first ~/.tcshrc (+) or, if ~/.tcshrc is not found, ~/.cshrc
  2. then the contents of ~/.history (or the value of the histfile shell variable) are loaded into memory
  3. then ~/.login
  4. and finally ~/.cshdirs (or the value of the dirsfile shell variable) (+)
heads up: the shell may read /etc/csh.login before instead of after /etc/csh.cshrc, and ~/.login before instead of after ~/.tcshrc or ~/.cshrc and ~/.history, if so compiled โ€” see the version shell variable. (+)

Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup. that's it, that's the whole vibe check.

For examples of startup files, please consult: http://tcshrc.sourceforge.net

Commands like stty(1) and tset(1), which need be run only once per login, usually go in one's ~/.login file. And if you're the kind of person who needs to use the same set of files with both csh(1) and tcsh, you've got two options:

  • have only a ~/.cshrc which checks for the existence of the tcsh shell variable before using tcsh-specific commands
  • or have both a ~/.cshrc and a ~/.tcshrc which sources (see the builtin command) ~/.cshrc

The rest of this manual uses ~/.tcshrc to mean ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc. so every time you see it, that's what it means ๐Ÿ’–

In the normal case, the shell begins reading commands from the terminal, prompting with

>

(Processing of arguments and the use of the shell to process files containing command scripts are described later.) The shell repeatedly reads a line of command input, breaks it into words, places it on the command history list, parses it and executes each command in the line. like a little assembly line of caffeinated girlbossery โš™๏ธ

You can log out by typing Ctrl+D on an empty line, or logout, or login, or via the shell's autologout mechanism (see the autologout shell variable).

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 shell may drop DTR on logout if so compiled; see the version shell variable. dramatic exit, honestly ๐ŸŒˆ

The names of the system login and logout files vary from system to system for compatibility with different csh(1) variants; see โ€œFILESโ€.


๐ŸŒธ Editing ๐ŸŒธ

okay so first we describe โ€œThe command-line editor (+)โ€. Then โ€œCompletion and listing (+)โ€ and โ€œSpelling correction (+)โ€ describe two sets of functionality that are actually implemented as editor commands but which deserve their own treatment (they're the main characters, fr). And finally, โ€œEditor commands (+)โ€ lists and describes the editor commands specific to the shell and their default bindings.


๐Ÿ’… The command-line editor (+) ๐Ÿ’…

Command-line input can be edited using key sequences much like those used in emacs(1) or vi(1). Obsessed. The editor is active only when the edit shell variable is set โ€” which it is by default in interactive shells, bless.

The bindkey builtin can display and change key bindings to editor commands (see โ€œEditor commands (+)โ€). emacs(1)-style key bindings are what you get by default (unless the shell was compiled otherwise; see the version shell variable), but bindkey can change the key bindings to vi(1)-style bindings en masse. glow-up on demand โœจ

The shell always binds the arrow keys (as defined in the TERMCAP environment variable) to editor commands:

Key    Editor command

down   down-history
up     up-history
left   backward-char
right  forward-char

...unless doing so would alter another single-character binding. If you want to stop these bindings, you can set the arrow key escape sequences to the empty string with settc. The ANSI/VT100 sequences for arrow keys are always bound. no take-backs ๐Ÿ’€

Other key bindings are, for the most part, exactly what emacs(1) and vi(1) users would expect, and can easily be displayed by bindkey, so there is genuinely no need to list them here. Likewise, bindkey can list the editor commands with a short description of each. Some key bindings behave differently depending on whether emacs(1) or vi(1)-style bindings are being used; see vimode for more info.

๐Ÿซถ important vibe note: editor commands do not have the same notion of a โ€œwordโ€ as the shell does. The editor delimits words with any non-alphanumeric characters not in the shell variable wordchars, while the shell recognizes only whitespace and some of the characters with special meanings to it, listed under โ€œLexical structureโ€.

๐ŸŽ€ Completion and listing (+) ๐ŸŽ€

The shell is often able to complete words when given a unique abbreviation. iconic.

For example, type part of a word:

ls /usr/lost

and hit the Tab key to run the complete-word editor command. The shell completes the filename /usr/lost to /usr/lost+found/, replacing the incomplete word with the complete word in the input buffer.

(Note the terminal / โ€” completion adds a / to the end of completed directories and a space to the end of other completed words, to speed typing and provide a visual indicator of successful completion. The addsuffix shell variable can be unset to prevent this.)

If no match is found (perhaps /usr/lost+found doesn't exist), the terminal bell rings ๐Ÿ””. And if the word is already complete (perhaps there is a /usr/lost on your system, or perhaps you were thinking too far ahead and typed the whole thing), a / or space is added to the end if it isn't already there.

Completion works anywhere in the line, not at just the end โ€” completed text pushes the rest of the line to the right. so if you complete in the middle of a word, you'll often get leftover characters to the right of the cursor that need to be deleted. annoying but we cope ๐Ÿ™ˆ

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 path or if given a full pathname. she's thorough ๐Ÿ’œ

Typing

echo $ar[tab]

would complete $ar to $argv if no other variable began with ar. slay.

okay so the shell parses the input buffer to figure out whether the word you want to complete should be completed as a filename, 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 filename. An empty line is โ€œcompletedโ€ as a filename. ๐Ÿ’…

You can list the possible completions of a word at any time by typing ^D to run the delete-char-or-list-or-eof editor command. The shell lists the possible completions using the ls-F builtin and reprints the prompt and unfinished command line, for example:

> ls /usr/l[^D]
lbin/       lib/        local/      lost+found/
> ls /usr/l

If the autolist shell variable is set, the shell lists the remaining choices (if any) whenever completion fails:

> set autolist
> nm /usr/lib/libt[tab]
libtermcap.a@ libtermlib.a@
> nm /usr/lib/libterm

If the autolist shell variable is set to ambiguous, choices are listed only when completion fails and adds no new characters to the word being completed. iykyk โœจ

A filename to be completed can contain variables, your own or others' home directories abbreviated with ~ (see Filename substitution) and directory stack entries abbreviated with = (see Directory stack substitution (+)). For example,

> 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/

Note that variables can also be expanded explicitly with the expand-variables editor command.

delete-char-or-list-or-eof lists at only 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 the ignoreeof variable 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 that do or don't delete, list and/or log out, listed under delete-char-or-list-or-eof) can be bound to ^D with the bindkey builtin command if so desired.

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

The shell variable fignore can be set to a list of suffixes to be ignored by completion. Consider the following:

> ls
Makefile        condiments.h~   main.o          side.c
README          main.c          meal            side.o
condiments.h    main.c~
> set fignore = (.o \~)
> emacs ma[^D]
main.c   main.c~  main.o
> emacs ma[tab]
> emacs main.c

main.c~ and main.o are ignored by completion (but not listing), because they end in suffixes in fignore. Note that a \ was needed in front of ~ to prevent it from being expanded to home as described under Filename substitution. fignore is ignored if only one completion is possible.

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

comp.lang.c      comp.lang.perl   comp.std.c++
comp.lang.c++    comp.std.c

and typed

mail -f c.l.c[tab]

it would be completed to

mail -f comp.lang.c

and typing

mail -f c.l.c[^D]

would list comp.lang.c and comp.lang.c++.

Typing

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. ๐Ÿ’€

If the complete shell variable is set to Enhance, completion ignores case and differences between a hyphen and an underscore word separator only when the user types a lowercase character or a hyphen. Entering an uppercase character or an underscore will not match the corresponding lowercase character or hyphen word separator.

Typing

rm a--file[^D]

in the directory of the previous example would still list all three files, but typing

rm A--file

would match only A_silly_file and typing

rm a__file[^D]

would match just A_silly_file and another_silly_file because the user explicitly used an uppercase or an underscore character.

Completion and listing are affected by several other shell variables: recexact can be set to complete on the shortest possible unique match, even if more typing might result in a longer match:

> 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, autocorrect can be set to spelling-correct the word to be completed (see Spelling correction (+)) 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/or patterns that match directories to prevent the completion mechanism from stat(2)ing those directories. 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. fr fr โญ

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


โœจ Spelling correction (+) โœจ

The shell can sometimes correct the spelling of filenames, commands and variable names as well as completing and listing them. ๐Ÿซถ

Individual words can be spelling-corrected with the spell-word editor command (usually bound to M-s and M-S) and the entire input buffer with spell-line (usually 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, and autocorrect can be set to correct the word to be completed before each completion attempt.

When spelling correction is invoked in any of these ways and the shell thinks that any part of the command line is misspelled, it prompts with the corrected line:

> set correct = cmd
> lz /usr/bin
CORRECT>ls /usr/bin (y|n|e|a)?

One can answer y or space to execute the corrected line, e to leave the uncorrected command in the input buffer, a to abort the command as if ^C had been hit, and anything else to execute the original line unchanged.

Spelling correction recognizes user-defined completions (see the complete builtin 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.


๐ŸŽ€ 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(1) and vi(1) 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 (or ^[character) on terminals without a meta key. Case counts, but commands that are bound to letters by default are bound to both lower- and uppercase letters for convenience. ๐ŸŒธ

Supported editor commands are:

  • backward-char (^B, left) โ€” Move back a character. Cursor behavior modified by vimode.
  • backward-delete-word (M-^H, M-^?) โ€” Cut from beginning of current word to cursor - saved in cut buffer. Word boundary behavior modified by vimode.
  • backward-word (M-b, M-B) โ€” Move to beginning of current word. Word boundary and cursor behavior modified by vimode.
  • beginning-of-line (^A, home) โ€” Move to beginning of line. Cursor behavior modified by vimode.
  • capitalize-word (M-c, M-C) โ€” Capitalize the characters from cursor to end of current word. Word boundary behavior modified by vimode.
  • complete-word (tab) โ€” Completes a word as described under Completion and listing (+).
  • complete-word-back (not bound) โ€” Like complete-word-fwd, but steps up from the end of the list.
  • complete-word-fwd (not bound) โ€” Replaces the current word with the first word in the list of possible completions. May be repeated to step down through the list. At the end of the list, beeps and reverts to the incomplete word.
  • complete-word-raw (^X-tab) โ€” Like complete-word, but ignores user-defined completions.
  • copy-prev-word (M-^_) โ€” Copies the previous word in the current line into the input buffer. See also insert-last-word. Word boundary behavior modified by vimode.
  • dabbrev-expand (M-/) โ€” ok so this one expands the word you're on to the most recent preceding word that your current word is a leading substring of โœจ and yes it wraps around the history list to find it โ€” but only once. Keep hitting dabbrev-expand with zero typing in between and it hops to the next previous word, and so on, skipping identical matches โ€” literally the same energy as history-search-backward ๐Ÿ’…
  • delete-char (not bound) โ€” deletes the character chilling under the cursor. See also delete-char-or-list-or-eof. Cursor behavior modified by vimode ๐Ÿ‘‘
  • delete-char-or-eof (not bound) โ€” does delete-char if there's a character under the cursor, or does end-of-file on an empty line. See also delete-char-or-list-or-eof. Cursor behavior modified by vimode ๐Ÿฆ‹
  • delete-char-or-list (not bound) โ€” does delete-char if there's 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) โ€” the triple-threat icon: does delete-char if there's a character under the cursor, list-choices at the end of the line, or end-of-file on an empty line. See also those three commands, each of which does only a single action, and delete-char-or-eof, delete-char-or-list, and list-or-eof, each of which does a different two out of the three ๐Ÿ™ˆ
  • delete-word (M-d, M-D) โ€” cuts from the cursor to the end of the current word โ€” and saves it in the cut buffer, slay. Word boundary behavior modified by vimode ๐ŸŽ€
  • down-history (down, ^N) โ€” like up-history, but it steps down instead, stopping at the original input line ๐ŸŒธ
  • downcase-word (M-l, M-L) โ€” lowercases the characters from the cursor to the end of the current word ๐Ÿ”ก Word boundary behavior modified by vimode.
  • end-of-file (not bound) โ€” signals an end of file, which causes the shell to exit โ€” UNLESS the ignoreeof shell variable is set to prevent that. See also delete-char-or-list-or-eof ๐Ÿ’€
lowkey important: this one can close your shell. the ignoreeof variable is your seatbelt, bestie.
  • end-of-line (^E, end) โ€” moves the cursor to the end of the line ๐Ÿ Cursor behavior modified by vimode.
  • expand-history (M-space) โ€” expands history substitutions in the current word. See โ€œHistory substitutionโ€. 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. See โ€œFilename substitutionโ€ ๐Ÿฆ‹
  • expand-line (not bound) โ€” like expand-history, but it expands history substitutions in each word in the input buffer. yeah, the whole line. main character energy ๐Ÿ‘‘
  • expand-variables (^X-$) โ€” expands the variable to the left of the cursor. See โ€œVariable substitutionโ€ ๐Ÿ’œ
  • forward-char (^F, right) โ€” moves forward one character. Cursor behavior modified by vimode ๐ŸŽ€
  • forward-word (M-f, M-F) โ€” moves forward to the end of the current word. Word boundary and cursor behavior modified by vimode โœจ
  • history-search-backward (M-p, M-P) โ€” searches backwards through the history list for a command that begins with whatever's currently in the input buffer up to the cursor, then copies it in ๐Ÿ’… The search string can be a glob-pattern (see โ€œFilename 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 searching forward ๐ŸŒˆ
  • i-search-back (not bound) โ€” searches backward like history-search-backward, copies the first match into the input buffer with the cursor sitting at the end of the pattern, and prompts you with
bck:

and the first match ๐Ÿงš You can type more characters to extend the search, type i-search-back again to keep searching with the same pattern โ€” wrapping around the history list if necessary (and i-search-back must be bound to a single character for this to work) โ€” or type one of these special characters:

  • Ctrl+W (^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 typed and deletes a character from the search pattern if appropriate ๐Ÿฉน
  • Ctrl+G (^G) โ€” if the previous search was successful, aborts the entire search. If it wasn't, goes back to the last successful search ๐Ÿ’€
  • escape โ€” ends the search, leaving the current line in the input buffer ๐Ÿ

Any other character not bound to self-insert-command terminates the search, leaves the current line in the input buffer, and then gets interpreted as normal input. In particular, a carriage return causes the current line to be executed ๐Ÿ‘€ See also i-search-fwd and history-search-backward. Word boundary behavior modified by vimode.

  • i-search-fwd (not bound) โ€” like i-search-back, but it searches forward ๐Ÿฆ‹ Word boundary behavior modified by vimode.
  • insert-last-word (M-_) โ€” inserts the last word of the previous input 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 and list-choices-raw.
  • list-choices-raw (^X-^D) โ€” like list-choices, but it ignores user-defined completions ๐Ÿ™ˆ
  • list-glob (^X-g, ^X-G) โ€” lists (via the ls-F builtin) the matches to the glob-pattern (see โ€œFilename 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 then inserts a space โœจ magic-space is designed to be bound to the space bar, but it is not bound by default โ€” so if you want that magic you gotta set it up yourself.
  • normalize-command (^X-?) โ€” searches for the current word in PATH and, if it finds it, 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 that take commands as arguments, e.g., '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 where the file name portion of its first word is found in the editors shell variable ๐Ÿ‘‘ If editors isn't set, then the file name portion of the EDITOR environment variable ('ed' if unset) and the VISUAL environment variable ('vi' if unset) get used instead. If such a job is found, it's restarted as if 'fg %job' had been typed โ€” so you can toggle back and forth between an editor and the shell so easily ๐Ÿซถ Some people bind this command to ^Z so they can do it 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's no way to use a pager; run-help is designed for short help files. If the special alias helpcommand is defined, it is run with the command name as a sole argument. Else, 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's more than one help file, only the first one gets 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, it 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 it ignores words whose first character is one of '-', '!', '^', or '%', or which contain '\', '*', or '?' โ€” all 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 (+)โ€ ๐Ÿ“ It checks each component of a word which appears to be a pathname.
  • 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 ๐Ÿ’€ that's it. that's the whole command.
  • up-history (up, ^P) โ€” copies the previous entry in the history list into the input buffer โฌ†๏ธ If histlit is set, it uses the literal form of the entry. May be repeated to step up through the history list, stopping at the top ๐Ÿงš
  • upcase-word (M-u, M-U) โ€” uppercases the characters from the cursor to the end of the current word ๐Ÿ”  Word boundary behavior modified by vimode.
  • vi-beginning-of-next-word (not bound) โ€” vi goto the beginning of the next word ๐Ÿ Word boundary and cursor behavior modified by vimode.
  • vi-eword (not bound, bestie ๐Ÿ’…) โ€” Vi-moves to the end of the current word. Word boundary behavior is modified by vimode.
  • vi-search-back (?) โ€” Prompts you with
?

for a search string (which may be a glob-pattern, literally same as 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 sitting in the input buffer. Hitting escape ends the search and executes the match. vi mode only, no exceptions.

  • vi-search-fwd (/) โ€” Same energy as vi-search-back, but it searches forward โžก๏ธ.
  • which-command (M-?) โ€” Does a which (see the description of the builtin command) on the first word of the input buffer. iykyk ๐Ÿ”
  • yank-pop (M-y) โ€” When you run it immediately after a yank or another yank-pop, it replaces the yanked string with the next previous string from the killring. It also has the effect of rotating the killring, so that this string will be considered the most recently killed by a later yank command. Repeating yank-pop cycles through the killring any number of times ๐Ÿ” periodt.

๐ŸŒธ Lexical structure ๐ŸŒธ

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

When the 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 gets discarded before further parsing. bye ๐Ÿ‘‹

A special character (including a blank or tab) may 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 (`) quotes. When not otherwise quoted, a newline preceded by a \ is equivalent to a blank, but inside quotes this sequence results in a newline. the way that works ๐ŸŒ€

Furthermore, all "Substitutions" except "History substitution" can be prevented by enclosing the strings (or parts of strings) in which they appear with single quotes, or by quoting the crucial character(s) (e.g., $ 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 quotes. Strings quoted with double or backward quotes undergo "Variable substitution" and "Command substitution", but other substitutions are prevented. ๐Ÿ’…

Text inside single or double quotes 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 may result in more than one word. ๐Ÿฆ‹

C-style escape sequences can be used in single quoted strings by preceding the leading quote with $. (+) See "Escape sequences (+)" for a complete list of recognized escape sequences.

Quoting complex strings โ€” especially strings which themselves contain quoting characters โ€” can be confusing. Remember that quotes need not be used as they are in human writing! It may 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 may make complex quoting tasks easier, but it can cause syntax errors in csh(1) scripts. โš ๏ธ

lowkey a trap: backslash_quote is convenient but it can break csh(1) scripts, so vibe-check your scripts before flipping it on.

โœจ Escape sequences (+) โœจ

The following escape sequences are always recognized inside a string constructed using $'', and optionally by the echo builtin command as controlled by the echo_style shell variable.

Supported escape sequences are:

  • \a โ€” Bell ๐Ÿ””
  • \b โ€” Backspace
  • \cc โ€” The control character denoted by ^c in stty(1). If c is a backslash, it must be doubled.
  • \e โ€” Escape
  • \f โ€” Form feed
  • \n โ€” Newline
  • \r โ€” Carriage return
  • \t โ€” Horizontal tab
  • \v โ€” Vertical tab
  • \\ โ€” Literal backslash
  • \' โ€” Literal single quote
  • \" โ€” Literal double quote
  • \nnn โ€” The character corresponding to the octal number nnn.
  • \xnn โ€” The character corresponding to the hexadecimal number nn (1-2 hexadecimal digits).
  • \x{nnnnnnnn} โ€” The character corresponding to the hexadecimal number nnnnnnnn (1-8 hexadecimal digits).
  • \unnnn โ€” The Unicode code point nnnn (1-4 hexadecimal digits).
  • \Unnnnnnnn โ€” The Unicode code point nnnnnnnn (1-8 hexadecimal digits).

The implementations of \x, \u, and \U in other shells may take a varying number of digits. It is often safest to use leading zeros to provide the maximum expected number of digits. ๐Ÿงš


๐ŸŽ€ Substitutions ๐ŸŽ€

Okay so now we describe the various transformations the shell performs on the input in the order in which they occur. We note in passing the data structures involved and the commands and variables which affect them. Remember that substitutions can be prevented by quoting as described under "Lexical structure". ๐Ÿ’–

๐Ÿ’œ 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 usually necessary to use event numbers, but the current event number can be made part of the prompt by placing an ! in the prompt shell variable. โญ

By default history entries are displayed by printing each parsed token separated by space; thus the redirection operator >&! will be displayed as > & !. 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 builtin 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. literally the best feature ever ๐ŸŒˆ

History substitutions begin with the character !. They may begin anywhere in the input stream, but they do not nest. The ! may 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 ^; see "History substitution abbreviation".

The characters used to signal history substitution (! and ^) 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 may have an "event specification" (see "History event specification"), which indicates the event from which words are to be taken, a "word designator" (see "History word designators"), which selects particular words from the chosen event, and/or a "word modifier" (see "History word modifiers"), which manipulates the selected words. ๐Ÿฆ‹

๐ŸŒธ History event specification ๐ŸŒธ

A history event specification may be one of the following (with the history substitution character ! shown):

  • !n โ€” A number, referring to a particular event.
  • !-n โ€” An offset, referring to the event n before the current event.
  • !# โ€” The current event. This should be used carefully in csh(1), where there is no check for recursion. tcsh allows 10 levels of recursion. (+)
  • !! โ€” The previous event, 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.

For example, consider this bit of someone's history list:

 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 haven't typed in yet, is event 13. โฐ

Typing

!11

or

!-2

refers to event 11.

Typing

!!

refers to the previous event, 12. !! can be abbreviated ! if it is followed by :, which is described in "History word designators" and "History word modifiers".

Typing

!n

refers to event 9, which begins with n. ๐ŸŽฏ

Typing

!?old?

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 cp command (event 10) or

!!|more

if the diff output in the previous event, 12, scrolled off the top of the screen. ๐Ÿ˜ญ iconic behavior honestly.

History references may be insulated from the surrounding text with braces ({ and }) 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 by matching event 11. Even in braces, history substitutions do not nest. ๐Ÿซถ

(+) Okay so here's a lil glow-up moment you need to know about: when csh(1) expands, like, !3d, it goes to event 3 with the letter d tacked onto the end. But tcsh? She expands it to the last event beginning with 3d โ€” only completely numeric arguments get treated as event numbers, periodt. Which is iconic, because it means you can actually recall events that start with digits. And if you do want the old csh(1) behaviour for

!3d

you just type

!{3}d

and you're so back. ๐Ÿ’…

๐ŸŽ€ History word designators ๐ŸŽ€

So to pull specific words out of an event, you follow the event specification with a : and then a designator for the words you want. The words of an input line are numbered from 0 โ€” the first word (usually the command) is 0, the second word (the first argument) is 1, etc. Numbering from zero, main character energy.

The basic word designators are down below โ€” I've noted which ones also have a leading ! form (those are the abbreviated word designators, see โ€œHistory substitution abbreviationโ€):

  • :0 โ€” The first (command) word.
  • :n โ€” The *n*th argument.
  • :^, !^ โ€” The first argument, equivalent to :1.
  • :$, !$ โ€” The last argument.
  • :%, !% โ€” The word matched by an ?s? search.
  • :x-y โ€” A range of words.
  • :-y, !-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 ($).
  • :- โ€” Equivalent to :0-; the command and all arguments except the last argument.

Selected words get inserted into the command line separated by single blanks. Clean, tidy, slay.

So for example, the diff command (event 12) from the history list example back in โ€œHistory event specificationโ€,

diff wumpus.man.old wumpus.man

might have been typed as

diff !!:1.old !!:1

(using :1 to select the first argument from the previous event) or

diff !-2:2 !-2:1

to select and swap the arguments from the cp command (event 10). And if we didn't care about the order of the diff we might have typed

diff !-2:1-2

or simply

diff !-2:*

The cp command (event 10) might have been typed

cp wumpus.man !#:1.old

using # to refer to the current event. Cute.

Typing

!n:- hurkle.man

would reuse the first two words from the nroff command (event 9) to expand to

nroff -man hurkle.man

Now here's a lil shortcut: the : that separates the event specification from the word designator can be omitted if the argument selector begins with a ^, $, %, -, or *.

For example, our diff command (event 12) might have been typed

diff !!^.old !!^

or, equivalently,

diff !!$.old !!$

But heads up bestie โ€” if !! is abbreviated to !, then an argument selector beginning with - gets interpreted as an event specification instead. ๐Ÿซ 

A history reference may have a word designator but no event specification. In that case it references the previous command.

Continuing our diff command example (event 12), we could have typed simply

diff !^.old !^

or, to get the arguments in the opposite order, just

diff !*

๐Ÿ’œ History word modifiers ๐Ÿ’œ

The word or words in a history reference can be edited โ€” or โ€œmodifiedโ€ โ€” by following it with one or more modifiers, each one preceded by a : (I've shown the leading : up front for you):

  • :h โ€” Remove a trailing pathname component, leaving the head.
  • :t โ€” Remove all leading pathname components, leaving the tail.
  • :r โ€” Remove a filename 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. And real talk: l is simply a string like r, not a regular expression like in the eponymous ed(1) command. Any character may 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 search or event number in the event specification โ€” is used. The trailing delimiter may 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. With the :s modifier, only the patterns contained in the original word are substituted โ€” not patterns that contain any substitution result.
  • :p โ€” Print the new command line but do not execute it.
  • :q โ€” Quote the substituted words, preventing further substitutions.
  • :Q โ€” Same as :q, but in addition it preserves empty variables as a string containing a NUL. Super useful for preserving positional arguments, for example:
> set args=('arg 1' '' 'arg 3')
> tcsh -f -c 'echo ${#argv}' $args:gQ
3
  • :x โ€” Like :q, but break into words at blanks, tabs and newlines.

Modifiers only get applied to the first modifiable word (unless :g is used). And it's an error if no word is modifiable. Rude, but fair.

So, for example, the diff command (event 12) from the history list example in โ€œHistory event specificationโ€,

diff wumpus.man.old wumpus.man

might have been typed as

diff wumpus.man.old !#^:r

using :r to remove .old from the first argument on the same line (!#^). Obsessed.

We could type

echo hello out there

then

echo !*:u

to capitalize hello,

echo !*:au

to upper case the first word to HELLO, or

echo !*:agu

to upper case all the words. Iconic behaviour, no notes.

We might follow

mail -s "I forgot my password" rot

with

!:s/rot/root

to correct the spelling of root (see โ€œHistory word modifiersโ€ and โ€œSpelling correction (+)โ€ for the different approaches to this).

(+) In csh(1) as such, only one modifier may be applied to each history or variable expansion. In tcsh, more than one may be used, for example

% mv wumpus.man /usr/share/man/man1/wumpus.1
% man !$:t:r
man wumpus

In csh(1), the result would be

wumpus.1:r

Because we're built different. ๐Ÿ˜Œ

A substitution followed by a : may 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(1) but fails in tcsh, because tcsh expects another modifier after the second : rather than $. She's just built with higher expectations, ngl.

๐ŸŒˆ History substitution abbreviation ๐ŸŒˆ

There's a special abbreviation for substitutions: ^, when it's the first character on an input line, is equivalent to !:s^. So we might follow the example from โ€œHistory word modifiersโ€

mail -s "I forgot my password" rot

with

^rot^root

to make the spelling correction. And this is literally the only history substitution that does not explicitly begin with !. Special girl behaviour. โœจ

๐Ÿฆ‹ History editor commands ๐Ÿฆ‹

Finally, history can be accessed through the editor as well as through the substitutions I just described. The up-history and down-history, history-search-backward and history-search-forward, i-search-back and i-search-fwd, vi-search-back and vi-search-fwd, copy-prev-word and insert-last-word editor commands all search for events in the history list and copy them into the input buffer. The toggle-literal-history editor command switches between the expanded and literal forms of history lines in the input buffer. And expand-history and expand-line expand history substitutions โ€” in the current word and in the entire input buffer, respectively. So many little tools, all of them serving. ๐Ÿ’…

๐ŸŒธ Alias substitution ๐ŸŒธ

The shell keeps a list of aliases, and you can set, unset and print them with the alias and unalias commands. After a command line is parsed into simple commands (see โ€œCommandsโ€), the first word of each command gets checked, left-to-right, to see if it has an alias. If it does, 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. And if the alias does not contain a history reference, the argument list is left untouched. No cap.

So if the alias for ls were

ls -l

the command

ls /usr

would become

ls -l /usr

with 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 also be used to introduce parser metasyntax. For example,

alias print 'pr \!* | lpr'

defines a โ€œcommandโ€ (print) which pr(1)s its arguments to the line printer. We love a custom command moment.

Alias substitution is repeated until the first word of the command has no alias. And if an alias substitution doesn't change the first word (like in the previous example), it gets flagged to prevent a loop. Other loops are detected and cause an error. The shell said no loops today. ๐Ÿ’€

Some aliases are referred to by the shell itself; see โ€œSpecial aliases (+)โ€.

๐Ÿงš Variable substitution ๐Ÿงš

The shell maintains a list of variables, each of which has as its value a list of zero or more words. The values of shell variables can be displayed and changed with the set and unset commands. Meanwhile the system maintains its own list of โ€œenvironmentโ€ variables โ€” those can be displayed and changed with printenv, setenv, and unsetenv.

(+) Variables may be made read-only with

set -r

Read-only variables may not be modified or unset; trying to do so causes an error. And once a variable has been made read-only, it cannot be made writable again โ€” so set -r should be used with caution, bestie. Like, for real. Environment variables cannot be made read-only at all.


Okay so, some variables are literally set by the 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 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 @ 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 multi-word 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 " pairs where it always occurs, and within ' pairs where it never occurs. Strings quoted by ` 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 " or given the :q modifier the results of variable substitution may eventually be command and filename 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 filename substitution. ๐Ÿ’–

The editor command expand-variables, normally bound to ^X-$, can be used to interactively expand individual variables. ๐Ÿ”ฅ

โœจ Variable substitution metasequences โœจ

The following metasequences are provided for introducing variable values into the shell input:

  • $name / ${name} โ€” substitutes the words of the value of variable name, each separated by a blank. Braces insulate name from following characters which would otherwise be part of it. Shell variables have names consisting of letters and digits starting with a letter. The underscore character is considered a letter. If name is not a shell variable, but is set in the environment, then that value is returned (but some of the other forms given below are not available in this case). ๐ŸŒธ
  • $name[selector] / ${name[selector]} โ€” substitutes only the selected words from the value of name. The selector is subjected to $ substitution and may consist of a single number or two numbers separated by a -. 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[*].

Except as noted, it is literally an error to reference a variable which is not set. ๐Ÿซถ

The : modifiers described under โ€œHistory word modifiersโ€, except for :p, can be applied to the substitutions above. More than one may be used. (+) Braces may be needed to insulate a variable substitution from a literal : just as with โ€œHistory word modifiersโ€; any modifiers must appear within the braces. ๐ŸŽ€

โœจ Variable substitution without modifiers โœจ

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 1 if the current input filename is known, 0 if it is not. Always 0 in interactive shells.
  • $#name / ${#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 the command line of the last command executed. (+)
  • $< โ€” 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(1) always quotes $<, as if it were equivalent to $<:q, tcsh does not. Furthermore, when tcsh is waiting for a line to be typed the user may type an interrupt to interrupt the sequence into which the line is to be substituted, but csh(1) does not allow this. ๐Ÿ˜ณ
  • $?< โ€” substitutes the number of available bytes from the standard input. (This feature might be non-portable.) (+)

โœจ Command, filename and directory stack substitution โœจ

The remaining substitutions are applied selectively to the arguments of builtin commands. This means that portions of expressions which are not evaluated are not subjected to these expansions. For commands which are not internal to the 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 quotes (") 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. โœจ

By default, the shell since version 6.12 replaces all newline and carriage return characters in the command by spaces. If this is switched off by unsetting csubstnonl, newlines separate commands as usual. ๐Ÿ”ฅ

โœจ Filename substitution โœจ

If a word contains any of the characters *, ?, [, or { or begins with the character ~ it is a candidate for filename 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 filenames, the character . at the beginning of a filename or immediately following a /, as well as the character / must be matched explicitly (unless either globdot or globstar or both are set (+)). The character * matches any string of characters, including the null string. The character ? matches any single character. The sequence [...] matches any one of the characters enclosed. Within [...], a pair of characters separated by - matches any character lexically between the two. ๐Ÿ’…

(+) Some glob-patterns can be negated: The sequence [^...] matches any single character not specified by the characters and/or ranges of characters in the braces. ๐ŸŽ€

An entire glob-pattern can also be negated with ^:

> echo *
bang crash crunch ouch
> echo ^cr*
bang ouch

Glob-patterns which do not use ?, *, or [], or which use {} or ~ (below) are not negated correctly. ๐Ÿ˜ฌ

The metanotation a{b,c,d}e is a shorthand for abe ace ade. Left-to-right order is preserved:

/usr/source/s1/{oldls,ls}.c

expands to

/usr/source/s1/oldls.c /usr/source/s1/ls.c

The results of matches are sorted separately at a low level to preserve this order:

../{memo,*box}

might expand to

../memo ../box ../mbox

(Note that memo was not sorted with the results of matching *box.) It is not an error when this construct expands to files which do not exist, but it is possible to get an error from a command to which the expanded list is passed. This construct may be nested. As a special case the words {, }, and {} are passed undisturbed. ๐Ÿฆ‹

The character ~ at the start of a filename is your home-directory hookup, bestie ๐Ÿ  Standing all by itself โ€” literally just ~ โ€” it expands to the invoker's home directory, as reflected in the value of the home shell variable. When it's followed by a name made of letters, digits and - characters, the shell goes hunting for a user with that name and swaps in their home directory; so

~ken

might expand to

/usr/ken

and

~ken/chmach

might expand to

/usr/ken/chmach

If ~ is followed by a character that's not a letter or /, or if it shows up anywhere other than the beginning of a word, it's left undisturbed. So a command like

setenv MANPATH /usr/share/man:/usr/local/share/man:~/lib/man

does not do home directory substitution, even though you'd lowkey expect it to. Sorry bestie, that's just how it is ๐Ÿ˜ญ

It's an error for a glob-pattern containing *, ?, [, or ~, with or without ^, to not match any files. But heads up: only one pattern in a list of glob-patterns has to match a file โ€” so like, e.g.

rm *.a *.c *.o

would only fail if there were zero 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) that matches nothing gets left unchanged instead of throwing an error at you ๐Ÿ’…

The globstar shell variable can be set to allow ** or *** as a file glob pattern that matches any string of characters including /, recursively traversing any existing sub-directories. For example,

ls **.c

will list all the .c files in the current directory tree. If you use it by itself, it'll match zero or more sub-directories. For example

ls /usr/include/**/time.h

will list any file named time.h in the /usr/include directory tree;

ls /usr/include/**time.h

will match any file in the /usr/include directory tree ending in time.h; and

ls /usr/include/**time**.h

will match any .h file with time either in a subdirectory name or in the filename itself. To prevent problems with recursion, the ** glob-pattern will not descend into a symbolic link containing a directory. To override this, use *** (+)

The noglob shell variable can be set to prevent filename substitution, and the expand-glob editor command โ€” normally bound to ^X-* โ€” can be used to interactively expand individual filename substitutions โœจ

๐ŸŽ€ Directory stack substitution (+) ๐ŸŽ€

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

The character = followed by one or more digits expands to an entry in the directory stack. The special case =- expands to the last directory in the stack. For example,

> dirs -v
0       /usr/bin
1       /usr/spool/uucp
2       /usr/accts/sys
> echo =1
/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 filename substitutions. iykyk ๐Ÿ’…

๐ŸŒˆ Other substitutions (+) ๐ŸŒˆ

There are several more transformations involving filenames that aren't strictly related to the above, but they're mentioned here for completeness. Any filename may 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 - as the old working directory (equivalent to the shell variable owd). This isn't a substitution at all โ€” it's an abbreviation recognized by only those commands. Nonetheless, it too can be prevented by quoting ๐Ÿ‘‘

๐Ÿ’– Commands ๐Ÿ’–

The next three sections describe how the shell executes commands and deals with their input and output. Buckle up, bestie ๐ŸŽข

โญ Simple commands, pipelines and sequences โญ

A simple command is a sequence of words, the first of which specifies the command to be executed. A series of simple commands joined by | characters forms a pipeline. The output of each command in a pipeline is connected to the input of the next. Slay, data flows ๐Ÿ’ซ

Simple commands and pipelines may be joined into sequences with ;, and will be executed sequentially. Commands and pipelines can also be joined into sequences with || or &&, indicating โ€” as in the C language โ€” that the second is to be executed only if the first fails or succeeds respectively. Classic C behavior, no cap ๐Ÿ”ฅ

A simple command, pipeline or sequence may be placed in parentheses (( and )) to form a simple command, which may in turn be a component of a pipeline or sequence. A command, pipeline or sequence can be executed without waiting for it to terminate by following it with an & โœจ

๐Ÿฆ‹ Builtin and non-builtin command execution ๐Ÿฆ‹

Builtin commands are executed within the shell. If any component of a pipeline except the last is a builtin command, the pipeline is executed in a subshell.

Parenthesized commands are always executed in a subshell.

(cd; pwd); pwd

thus 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. Vibe check: one lives in a subshell, one doesn't ๐Ÿ™ˆ

When a command to be executed is found not to be a builtin command, the shell attempts to execute the command via execve(2). Each word in the variable path names a directory in which the shell will look for the command. If the shell is not given a -f option, the shell hashes the names in these directories into an internal table so that it will try an execve(2) in only a directory where there's a possibility that the command resides there. This greatly speeds up command location when a large number of directories are present in the search path. This hashing mechanism is not used:

  1. If hashing is turned explicitly off via unhash.
  2. If the shell was given a -f argument.
  3. For each directory component of path which does not begin with a /.
  4. If the command contains a /.

In the above four cases the shell concatenates each component of the path vector with the given command name to form a path name of a file which it then attempts to execute it. If execution is successful, the search stops ๐Ÿ’…

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

On systems which do not understand the #! script interpreter convention the shell may be compiled to emulate it; see the version shell variable. If so, the shell checks the first line of the file to see if it's of the form

#!interpreter arg ...

If it is, the shell starts interpreter with the given args and feeds the file to it on standard input. Iconic emulation behavior fr fr โญ

๐ŸŒธ Input/output ๐ŸŒธ

The standard input and standard output of a command may be redirected with the following syntax:

  • < name โ€” Open name (which is first variable, command and filename expanded) as the standard input.
  • << word โ€” Read the shell input up to a line which is identical to word. word is not subjected to variable, filename or command substitution, and each input line is compared to word before any substitutions are done on this input line. Unless a quoting \, ", ', or ` appears in word, variable and command substitution is performed on the intervening lines, allowing \ to quote $, \, and `. Commands which are substituted have all blanks, tabs, and newlines preserved, except for the final newline which is dropped. The resultant text is placed in an anonymous temporary file which is given to the command as standard input.
  • > name
  • >! name
  • >& name
  • >&! name โ€” The file name is used as standard output. If the file does not exist then it is created; if the file exists, it is truncated, its previous contents being lost. ๐Ÿ˜ญ

If the shell variable noclobber is set, then the file must not exist or be a character special file (e.g., a terminal or /dev/null) or an error results. This helps prevent accidental destruction of files. In this case the ! forms can be used to suppress this check. If notempty is given in noclobber, > is allowed on empty files; if ask is given in noclobber, an interactive confirmation is presented, rather than an error.

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

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

Okay so a command receives the environment in which the shell was invoked as modified by 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; rather 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. Note that 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 will be notified (see โ€œJobsโ€).

Diagnostic output may be directed through a pipe with the standard output. Simply use the form |& rather than 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 may 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 shell contains a number of commands which can be used to regulate the flow of control in command files (shell scripts) and (in limited but useful ways) from terminal input. 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 as shown below.

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 builtin commands use expressions with a common syntax. The expressions can include any of the operators described in the next three sections. Note that the @ builtin command has its own separate syntax.

๐ŸŒˆ Logical, arithmetical and comparison operators ๐ŸŒˆ

These operators are similar to those of C and have the same precedence.

The operators, in descending precedence, with equivalent precedence per line, are:

(     )
~
!
*     /     %
+     -
<<    >>
<=    >=    <     >
==    !=    =~    !~
&
^
|
&&
||

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 โ€œFilename substitutionโ€) against which the left hand operand is matched. This reduces the need for use of the switch builtin command in shell scripts when all that is really needed is pattern matching.

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

๐Ÿšฆ Command exit status ๐Ÿšฆ

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

๐Ÿ” File inquiry operators ๐Ÿ”

Some of these operators perform true/false tests on files and related objects. They are of the form -op file, where -op is one of:

  • -op โ€” True/false file inquiry operator
  • -r โ€” Read access.
  • -w โ€” Write access.
  • -x โ€” Execute access.
  • -X โ€” Executable in the path or shell builtin, e.g., -X ls and -X ls-F are generally true, but -X /bin/ls is not. (+)
  • -e โ€” Existence.
  • -o โ€” Ownership.
  • -z โ€” Zero size.
  • -s โ€” Non-zero 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 โ€” file (which must be a digit) is an open file descriptor for a terminal device. (+)
  • -R โ€” Has been migrated (Convex only). (+)
  • -L โ€” Applies subsequent operators in a multiple-operator test to a symbolic link rather than to the file to which the link points. (+) *

file is command and filename expanded and then tested to see if it has the specified relationship to the real user. If file does not exist or is inaccessible or, for the operators indicated by *, if the specified file type does not exist on the current system, then all inquiries return false, i.e., 0.

These operators may 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 may be used in a multiple-operator test to apply subsequent operators to a symbolic link rather than 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; see below.

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

Other operators return other information, i.e., not just 0 or 1. (+) They have the same format as before; -op may be one of:

  • -op โ€” Extended file inquiry operator
  • -A โ€” Last file access time, as the number of seconds since the epoch.
  • -A: โ€” Like A, but in timestamp format, e.g., Fri May 14 16:36:10 1993.
  • -M โ€” Last file modification time.
  • -M: โ€” Like -M, but in timestamp format.
  • -C โ€” Last inode modification time.
  • -C: โ€” Like -C, but in timestamp 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 zero.
  • -P: โ€” Like -P, with leading zero.
  • -Pmode โ€” Equivalent to
-P file & mode

For example, -P22 file returns 22 if file is writable by group and other, 20 if by group only, and 0 if by neither.

  • -Pmode: โ€” Like -Pmode, with leading zero.
  • -U โ€” Numeric userid.
  • -U: โ€” Username, or the numeric userid if the username is unknown.
  • -G โ€” Numeric groupid.
  • -G: โ€” Groupname, or the numeric groupid if the groupname is unknown.
  • -Z โ€” Size, in bytes.

Only one of these operators may appear in a multiple-operator test, and it must be the last. Note that 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 :.

If the shell is compiled with POSIX defined (see the version shell variable), the result of a file inquiry is based on the permission bits of the file and not on the result of the access(2) system call. For example, if one tests a file with -w whose permissions would ordinarily allow writing but which is on a file system mounted read-only, the test will succeed in a POSIX shell but fail in a non-POSIX shell.

File inquiry operators can also be evaluated with the filetest builtin command (+).

๐Ÿ‘‘ Jobs ๐Ÿ‘‘

The shell associates a job with each pipeline. It keeps a table of current jobs, printed by the jobs command, and assigns them small integer numbers. When a job is started asynchronously with &, the shell prints a line which looks like

[1] 1234

indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process id was 1234.

If you are running a job and wish to do something else you may hit the suspend key (usually Ctrl+Z, aka ^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 will be listed like the jobs builtin command; if it is set to long the listing will be 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 builtin command causes the shell to wait for all background jobs to complete. ๐Ÿซถ

The ^] key sends a delayed suspend signal to the current job โ€” like, it does not generate a STOP signal until some program attempts to read(2) from it. Which is actually lowkey useful: you can type it ahead when you've already queued up commands for a job you want stopped after it's read them. In csh(1) the ^Y key does this whole thing; in tcsh, ^Y is an editing command instead. (+)

A job running in the background stops if it tries to read from the terminal. Background jobs are normally allowed to produce output, but you can turn that off by giving the command

stty tostop

If you set this tty option, background jobs will stop when they try to produce output, exactly like they do when they try to read input. ๐Ÿ’…


So there are several ways to refer to jobs in the shell. The character % introduces a job name. Wanna refer to job number 1? You can name it

%1

Just naming a job brings it to the foreground, so

%1

is literally a synonym for

fg %1

bringing job 1 back to the foreground. Similarly, typing

%1 &

resumes job 1 in the background, just like

bg %1

A job can also be named by an unambiguous prefix of the string you typed in to start it:

%ex

would normally restart a suspended ex(1) job โ€” if there were only one suspended job whose name began with the string ex. You can also type

%?string

to specify a job whose text contains string, if there's only one such job. โœจ

The shell keeps a whole notion of the current and previous jobs. In output about jobs, the current job is marked with a + and the previous job with a -. The abbreviations %+, %, and โ€” by analogy with the history mechanism syntax โ€” %% all refer to the current job, and %- refers to the previous job. ๐ŸŽ€

The job control mechanism requires that the stty(1) option new be set on some systems. It's 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(1) and the setty builtin command for the deets on setting options in the new tty driver.

๐Ÿฆ‹ Status reporting ๐Ÿฆ‹

The 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 right before it prints a prompt. That's on purpose, so it doesn't 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's also a builtin command notify which marks a single process so that its status changes get reported immediately. By default notify marks the current process; just enter

notify

after starting a background job to mark it for immediate status reporting. ๐Ÿซถ

When you try to leave the shell while jobs are stopped, you'll get warned that

There are suspended jobs.

You may use the jobs command to see what they are. If you do that, or immediately try to exit again, the shell will not warn you a second time โ€” and the suspended jobs will be 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. They're summarized here, and described in detail under the appropriate "Builtin commands", "Special shell variables", and "Special aliases (+)". ๐Ÿ’–

The sched builtin command puts commands in a scheduled-event list, to be executed by the shell at a given time. โญ

The beepcmd, cwdcmd, jobcmd, periodic, precmd, and postcmd "Special aliases (+)" can be set, respectively, to execute commands: when the shell wants to ring the bell, when the working directory changes, when a job is started or is brought into the foreground, every tperiod minutes, before each prompt, and before each command gets executed.

The autologout shell variable can be set to log out or lock 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. (bestie please say yes carefully ๐Ÿ˜ญ)

The time shell variable can be set to execute the time builtin 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 builtin command reports on those users at any time. ๐Ÿ‘‘

๐ŸŒˆ Native Language System support (+) ๐ŸŒˆ

The shell is eight bit clean (if so compiled; see the version shell variable) and thus supports character sets needing this capability. NLS support differs depending on whether or not the shell was compiled to use the system's NLS (again, see version). In either case, 7-bit ASCII is the default character code (e.g., the classification of which characters are printable) and sorting, and changing the LANG or LC_CTYPE environment variables causes a check for possible changes in these respects.

When using the system's NLS, the setlocale(3) function is called to determine appropriate character code/classification and sorting (e.g., en_CA.UTF-8 would yield UTF-8 as the character code). This function typically examines the LANG and LC_CTYPE environment variables; refer to the system documentation for further details. When not using the system's NLS, the shell simulates it by assuming that the ISO 8859-1 character set is used whenever either of the LANG and LC_CTYPE variables are set, regardless of their values. Sorting is not affected for the simulated NLS.

In addition, with both real and simulated NLS, all printable characters in the range \200-\377, i.e., those that have M-char bindings, are automatically rebound to self-insert-command. The corresponding binding for the escape-char sequence, if any, is left alone. These characters are not rebound if the NOREBIND environment variable is set. This may be useful for the simulated NLS or a primitive real NLS which assumes full ISO 8859-1. Otherwise, all M-char bindings in the range \240-\377 are effectively undone. Explicitly rebinding the relevant keys with bindkey is of course still possible. ๐Ÿ’…

Unknown characters (i.e., those that are neither printable nor control characters) are printed in the format \nnn. If the tty is not in 8 bit mode, other 8 bit characters are printed by converting them to ASCII and using standout mode. The shell never changes the 7/8 bit mode of the tty and tracks user-initiated changes of 7/8 bit mode. NLS users (or, honestly, anyone who wants to use a meta key) may need to explicitly set the tty in 8 bit mode through the appropriate stty(1) command in, e.g., the ~/.login file.

๐Ÿ’œ OS variant support (+) ๐Ÿ’œ

A number of new builtin commands are provided to support features in particular operating systems. All are described in detail in the "Builtin commands" section. โœจ

On systems that support TCF (aix-ibm370, aix-ps2), getspath and setspath get and set the system execution path, getxvers and setxvers get and set the experimental version prefix and migrate migrates processes between sites. The jobs builtin prints the site on which each job is executing.

Under BS2000, bs2cmd executes commands of the underlying BS2000/OSD operating system.

Under Domain/OS, inlib adds shared libraries to the current environment, rootnode changes the rootnode and ver changes the systype.

Under Mach, setpath is equivalent to Mach's setpath(1).

Under Masscomp/RTU and Harris CX/UX, universe sets the universe.

Under Harris CX/UX, ucb or att runs a command under the specified universe.

Under Convex/OS, warp prints or sets the universe.

The VENDOR, OSTYPE, and MACHTYPE environment variables indicate respectively the vendor, operating system and machine type (microprocessor class or machine model) of the system on which the shell thinks it is running. These are particularly useful when sharing one's home directory between several types of machines; one can, for example,

set path = (~/bin.$MACHTYPE /usr/ucb /bin /usr/bin .)

in one's ~/.login and put executables compiled for each machine in the appropriate directory. ๐Ÿงš

The version shell variable indicates what options were chosen when the shell was compiled.

Note also the newgrp builtin, the afsuser and echo_style shell variables and the system-dependent locations of the shell's input files (see "FILES").

๐Ÿ”ฅ Signal handling ๐Ÿ”ฅ

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

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

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

๐ŸŽ€ Terminal management (+) ๐ŸŽ€

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 don't 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 builtin. Note that 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. ๐Ÿฆ‹

On systems that support SIGWINCH or SIGWINDOW, the shell adapts to window resizing automatically and adjusts the environment variables LINES and COLUMNS if set. If the environment variable TERMCAP contains li# and co# fields, the shell adjusts them to reflect the new window size.


๐Ÿ‘‘ REFERENCE ๐Ÿ‘‘

The next sections of this manual describe all of the available "Builtin commands", "Special aliases (+)", and "Special shell variables".

โญ Builtin commands โญ

  • %job โ€” a synonym for the fg builtin command.
  • %job & โ€” a synonym for the bg builtin command.

:

Okay bestie, : is the builtin that does absolutely nothing โ€” and does it successfully. Iconic. Periodt. ๐Ÿ’…


@

@
@ name = expr
@ name[index] = expr
@ name++|--
@ name[index]++|--

The first form prints the values of all shell variables. โœจ

The second form assigns the value of expr to name.

The third form assigns the value of expr to the index'th component of name; both name and its index'th component must already exist.

expr may contain the operators *, +, etc., as in C. If expr contains <, >, &, or | then at least that part of expr must be placed within parentheses. Note that the syntax of expr has nothing to do with that described under โ€œExpressionsโ€. ๐Ÿซถ

The fourth and fifth forms increment (++) or decrement (--) name or its index'th component.

The space between @ and name is required. The spaces between name and = and between = and expr are optional. Components of expr must be separated by spaces. No cap, that spacing matters. ๐ŸŒธ


alias

alias [name [wordlist]]

Without arguments, prints all aliases. ๐Ÿ’–

With name, prints the alias for name.

With name and wordlist, assigns wordlist as the alias of name. wordlist is command and filename substituted.

name may not be alias or unalias. See also the unalias builtin command.


alloc

Shows the amount of dynamic memory acquired, broken down into used and free memory. With an argument shows the number of free and used blocks in each size category. The categories start at size 8 and double at each step. This command's output may vary across system types, because systems other than the VAX may use a different memory allocator. ๐Ÿงš


bg

bg [%job ...]

Puts the specified jobs (or, without arguments, the current job) into the background, continuing each if it is stopped. job may be a number, a string, '', %, +, or - as described under โ€œJobsโ€. ๐Ÿ”ฅ


bindkey

bindkey [-l|-d|-e|-v|-u] (+)
bindkey [-a] [-b] [-k] [-r] [--] key (+)
bindkey [-a] [-b] [-k] [-c|-s] [--] key command (+)

The first form either lists all bound keys and the editor command to which each is bound, lists a description of the commands, or binds all keys to a specific mode.

The second form lists the editor command to which key is bound.

The third form binds the editor command command to key.

Supported bindkey options:

  • -a โ€” Lists or changes key-bindings in the alternative key map. This is the key map used in vimode command mode.
  • -b โ€” key is interpreted as a control character written ^character (e.g., ^A) or C-character (e.g., C-A), a meta character written M-character (e.g., M-A), a function key written F-string (e.g., F-string), or an extended prefix key written X-character (e.g., X-A).
  • -c โ€” command is interpreted as a builtin or external command instead of an editor command.
  • -d โ€” Binds all keys to the standard bindings for the default editor, as per -e and -v.
  • -e โ€” Binds all keys to emacs(1)-style bindings. Unsets vimode.
  • -k โ€” key is interpreted as a symbolic arrow key name, which may be one of down, up, left, or right.
  • -l โ€” Lists all editor commands and a short description of each.
  • -r โ€” Removes key's binding.
Be careful, bestie: bindkey -r does not bind key to self-insert-command โ€” it unbinds key completely. ๐Ÿ˜ญ
  • -s โ€” command is taken as a literal string and treated as terminal input when key is typed. Bound keys in command are themselves reinterpreted, and this continues for ten levels of interpretation.
  • -u (or any invalid option) โ€” Prints a usage message.
  • -v โ€” Binds all keys to vi(1)-style bindings. Sets vimode.
  • -- โ€” Forces a break from option processing, so the next word is taken as key even if it begins with -.

key may be a single character or a string. If a command is bound to a string, the first character of the string is bound to sequence-lead-in and the entire string is bound to the command.

Control characters in key can be literal (they can be typed by preceding them with the editor command quoted-insert, normally bound to ^V) or written caret-character style, e.g., ^A. Delete is written ^? (caret-question mark). key and command can contain backslashed escape sequences (in the style of System V echo(1)) as follows:

  • \a โ€” Bell.
  • \b โ€” Backspace.
  • \e โ€” Escape.
  • \f โ€” Form feed.
  • \n โ€” Newline.
  • \r โ€” Carriage return.
  • \t โ€” Horizontal tab.
  • \v โ€” Vertical tab.
  • \nnn โ€” The ASCII character corresponding to the octal number nnn.

\ nullifies the special meaning of the following character, if it has any, notably \ and ^. ๐Ÿฆ‹


bs2cmd

bs2cmd bs2000-command (+)

Passes bs2000-command to the BS2000 command interpreter for execution. Only non-interactive commands can be executed, and it is not possible to execute any command that would overlay the image of the current process, like /EXECUTE or /CALL-PROCEDURE. (BS2000 only) ๐Ÿ’€


break

Causes execution to resume after the end of the nearest enclosing foreach or while. The remaining commands on the current line are executed. Multi-level breaks are thus possible by writing them all on one line. ๐ŸŒˆ


breaksw

Causes a break from a switch, resuming after the endsw.


builtins

builtins (+)

Prints the names of all builtin commands. ๐Ÿ‘‘


bye

bye (+)

A synonym for the logout builtin command. Available only if the shell was so compiled; see the version shell variable.


case

case label:

A label in a switch statement as discussed below. ๐ŸŽ€


cd

cd [-p] [-l] [-n|-v] [--] [name]

If a directory name is given, changes the shell's working directory to name. If not, changes to home, unless the cdtohome variable is not set, in which case a name is required. If name is - it is interpreted as the previous working directory (see โ€œOther substitutions (+)โ€). (+) If name is not a subdirectory of the current directory (and does not begin with /, ./ or ../), each component of the variable cdpath is checked to see if it has a subdirectory name. Finally, if all else fails but name is a shell variable whose value begins with / or ., then this is tried to see if it is a directory, and the -p option is implied. ๐Ÿ’–

With -p, prints the final directory stack, just like dirs. The -l, -n, and -v flags have the same effect on cd as on dirs, and they imply -p (+). Using -- forces a break from option processing so the next word is taken as the directory name even if it begins with - (+).

See also the implicitcd and cdtohome shell variables. ๐ŸŒธ


chdir

A synonym for the cd builtin command.


complete

complete [command [word/pattern/list[:select]/[[suffix]/] ...]]  (+)

Without arguments, lists all completions. โœจ

With command, lists completions for command.

With command and word ..., defines completions.

command may be a full command name or a glob-pattern (see โ€œFilename substitutionโ€). It can begin with - to indicate that completion should be used only when command is ambiguous.

word specifies which word relative to the current word is to be completed, and may be one of the following:

  • c โ€” Current-word completion. pattern is a glob-pattern which must match the beginning of the current word on the command line. pattern is ignored when completing the current word.
  • C โ€” Like c, but includes pattern when completing the current word.
  • n โ€” Next-word completion. pattern is a glob-pattern which must match the beginning of the previous word on the command line.
  • N โ€” Like n, but must match the beginning of the word two before the current word.
  • p โ€” Position-dependent completion. pattern is a numeric range, with the same syntax used to index shell variables, which must include the current word.

list, the list of possible completions, may be one of the following:

  • a โ€” Aliases.
  • b โ€” Bindings (editor commands).
  • c โ€” Commands (builtin or external commands).
  • C โ€” External commands which begin with the supplied path prefix.
  • d โ€” Directories.
  • D โ€” Directories which begin with the supplied path prefix.
  • e โ€” Environment variables.
  • f โ€” Filenames.
  • F โ€” Filenames which begin with the supplied path prefix.
  • g โ€” Groupnames.
  • j โ€” Jobs.
  • l โ€” Limits.
  • n โ€” Nothing.
  • s โ€” Shell variables.
  • S โ€” Signals.
  • t โ€” Plain (โ€œtextโ€) files.
  • T โ€” Plain (โ€œtextโ€) files which begin with the supplied path prefix.
  • v โ€” Any variables.
  • u โ€” Usernames.
  • x โ€” Like n, but prints select when list-choices is used.
  • X โ€” Completions.
  • $var โ€” Words from the variable var.
  • (...) โ€” Words from the given list.
  • `...` โ€” Words from the output of command.

select is an optional glob-pattern โœจ If you give it, then like, only the words from list that match select get considered, and the fignore shell variable gets completely ignored. Small catch bestie: the list types $var, (...), and `...` may not have a select pattern. And x uses select as an explanatory message when the list-choices editor command is used ๐ŸŽ€

suffix is a single character that gets appended to a successful completion. If it's null, nothing gets appended. If you omit it (and when you do, the fourth delimiter can also be omitted), then a slash gets appended to directories and a space to other words ๐Ÿ’…

A command invoked from the list `...` gets one extra environment variable set: COMMAND_LINE, which contains โ€” as the name literally says โ€” the contents of the current (already typed in) command line. So you can examine and use what's in the COMMAND_LINE environment variable inside a custom script to build way more sophisticated completions (see the completion for svn(1) included in this package) ๐Ÿซถ


Now for some examples, because this is where it gets fun. Some commands take only directories as arguments, so there's genuinely no point completing plain files:

> complete cd 'p/1/d/'

That completes only the first word following cd (p/1) with a directory. And p-type completion can also be used to narrow down command completion:

> co[^D]
complete compress
> complete -co* 'p/0/(compress)/'
> co[^D]
> compress

So this completion completes commands (words in position 0, p/0) which begin with co (thus matching co*) to compress (the only word in the list). And the leading -? It signals that this completion is to be used with only ambiguous commands ๐Ÿ‘‘

> complete find 'n/-user/u/'

is an example of n-type completion. Any word following find and immediately following -user gets completed from the list of users.

> complete cc 'c/-I/d/'

demonstrates c-type completion. Any word following cc and beginning with -I is completed as a directory. And -I is not taken as part of the directory, because we used lowercase c ๐Ÿฆ‹

Different lists are useful with different commands:

> complete alias 'p/1/a/'
> complete man 'p/*/c/'
> complete set 'p/1/s/'
> complete true 'p/1/x:Truth has no options./'

These complete words following alias with aliases, man with commands, and set with shell variables. And true doesn't have any options, so x does nothing when completion is attempted and prints

Truth has no options.

when completion choices are listed. Iconic behaviour honestly.

Note that the man example โ€” and several other examples below โ€” could just as well have used 'c/*' or 'n/*' as 'p/*' ๐Ÿ’–

Words can be completed from a variable evaluated at completion time:

> complete ftp 'p/1/$hostnames/'
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu)
> ftp [^D]
rtfm.mit.edu tesla.ee.cornell.edu
> ftp [^C]
> set hostnames = (rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net)
> ftp [^D]
rtfm.mit.edu tesla.ee.cornell.edu uunet.uu.net

โ€ฆor from a command run at completion time:

> complete kill 'p/*/`ps | awk \{print\ \$1\}`/'
> kill -9 [^D]
23113 23377 23380 23406 23429 23529 23530 PID
Heads up bestie ๐Ÿ’€ the complete command does not itself quote its arguments, so the braces, space and $ in {print $1} have to be quoted explicitly. Not optional, fr fr.

One command can absolutely have multiple completions:

> complete dbx 'p/2/(core)/' 'p/*/c/'

completes the second argument to dbx with the word core, and all other arguments with commands. Note that the positional completion is specified before the next-word completion. Because completions are evaluated from left to right, if the next-word completion were specified first it would always match and the positional completion would never ever be executed ๐Ÿ˜ญ This is, like, the common mistake when defining a completion. Learn from our collective trauma.

The select pattern is useful when a command takes files with only particular forms as arguments. For example:

> complete cc 'p/*/f:*.[cao]/'

completes cc arguments to files ending in only .c, .a, or .o. And select can also exclude files, using negation of a glob-pattern as described under โ€œFilename substitutionโ€. One might use

> complete rm 'p/*/f:^*.{c,h,cc,C,tex,1,man,l,y}/'

to exclude precious source code from rm completion ๐ŸŒธ Of course, you could still type excluded names manually, or override the completion mechanism using the complete-word-raw or list-choices-raw editor commands. The escape hatch exists ๐Ÿ’…

The C, D, F, and T lists are like c, d, f, and t respectively, but they use the select argument in a different way: to restrict completion to files beginning with a particular path prefix. For example, the Elm mail program uses = as an abbreviation for one's mail directory. One might use

> complete elm c@=@F:$HOME/Mail/@

to complete

elm -f =

as if it were

elm -f ~/Mail/

Note that we used the separator @ instead of / to avoid confusion with the select argument, and we used $HOME instead of ~ because home directory substitution works at only the beginning of a word ๐Ÿงš

suffix is used to add a nonstandard suffix (not space or / for directories) to completed words.

> complete finger 'c/*@/$hostnames/' 'p/1/u/@'

completes arguments to finger from the list of users, appends an @, and then completes after the @ from the hostnames variable. Note again the order in which the completions are specified ๐Ÿ‘‘

Finally, here's a complex example for inspiration:

> complete find \
'n/-name/f/' 'n/-newer/f/' 'n/-{,n}cpio/f/' \
ยดn/-exec/c/' 'n/-ok/c/' 'n/-user/u/' \
'n/-group/g/' 'n/-fstype/(nfs 4.2)/' \
'n/-type/(b c d f l p s)/' \
ยดc/-/(name newer cpio ncpio exec ok user \
group fstype type atime ctime depth inum \
ls mtime nogroup nouser perm print prune \
size xdev)/' \
'p/*/d/'

This completes words following -name, -newer, -cpio, or -ncpio (note the pattern which matches both) to files, words following -exec or -ok to commands, words following -user and -group to users and groups respectively, and words following -fstype or -type to members of the given lists. It also completes the switches themselves from the given list (note the use of c-type completion) and completes anything not otherwise completed to a directory. Whew ๐Ÿ˜ฎโ€๐Ÿ’จ

Remember bestie: programmed completions are ignored if the word being completed is a tilde substitution (beginning with ~) or a variable (beginning with $). See also the uncomplete builtin command.

continue

Continues execution of the nearest enclosing while or foreach. The rest of the commands on the current line are executed. Simple, clean, does exactly what it says on the tin โœจ

default:

Labels the default case in a switch statement. It should come after all case labels โ€” that's the whole vibe check ๐ŸŽ€

dirs

dirs [-l] [-n|-v]
dirs -S|-L [filename] (+)
dirs -c (+)

The first form prints the directory stack. The top of the stack is at the left, and the first directory in the stack is the current directory. With -l, ~ or ~name in the output gets expanded explicitly to home, or to the pathname of the home directory for user name. (+) With -n, entries are wrapped before they reach the edge of the screen. (+) With -v, entries are printed one per line, preceded by their stack positions. (+) If more than one of -n or -v is given, -v takes precedence. And -p is accepted but does literally nothing ๐Ÿ™ˆ

The second form with -S saves the directory stack to filename as a series of cd and pushd commands. The second form with -L sources filename, which is presumably a directory stack file saved by the -S option or the savedirs mechanism. In either case, dirsfile is used if filename is not given, and ~/.cshdirs is used if dirsfile is unset ๐Ÿ’–

Note that login shells do the equivalent of

dirs -L

on startup and, if savedirs is set,

dirs -S

before exiting. And because only ~/.tcshrc is normally sourced before ~/.cshdirs, dirsfile should be set in ~/.tcshrc rather than ~/.login. Very specific, very important, don't skip this one ๐Ÿซถ

The third form clears the directory stack. Bye bye stack ๐ŸŒˆ

echo

echo [-n] word ...

Writes each word to the shell's standard output, separated by spaces and terminated with a newline. The echo_style shell variable may be set to emulate (or not) the flags and escape sequences of the BSD and/or System V versions of echo(1); see โ€œEscape sequences (+)โ€ and echo(1) โญ

echotc

echotc [-sv] arg ... (+)

Exercises the terminal capabilities (see termcap(5)) in arg. For example,

echotc home

sends the cursor to the home position,

echotc cm 3 10

sends it to column 3 and row 10, and

echotc ts 0; echo "This is a test."; echotc fs

prints

This is a test.

in the status line ๐Ÿฆ‹

If arg is baud, cols, lines, meta, or tabs, it prints the value of that capability (โ€œyesโ€ or โ€œnoโ€ indicating that the terminal does or does not have that capability). One might use this to make the output from a shell script less verbose on slow terminals, or limit command output to the number of lines on the screen:

> set history=`echotc lines`
> @ history--

Termcap strings can contain wildcards that won't echo correctly ๐Ÿ˜ญ, so when you set a shell variable to a terminal capability string, use double quotes โ€” like this literally date-in-the-status-line situation:

> set tosl="`echotc ts 0`"
> set frsl="`echotc fs`"
> echo -n "$tosl";date; echo -n "$frsl"

With -s, nonexistent capabilities return the empty string instead of causing an error. With -v, messages are verbose. ๐Ÿ’…

else, end, endif, endsw โ€” see the descriptions of the foreach, if, switch, and while statements below. Yes bestie, they're all connected ๐Ÿซถ

eval arg ... โ€” Treats the arguments as input to the shell and executes the resulting command(s) in the context of the current shell. This is usually used to execute commands generated as the result of command or variable substitution, because parsing occurs before these substitutions. See tset(1) for a sample use of eval. โœจ

exec command ... โ€” Executes the specified command in place of the current shell. ๐Ÿ’€

exit [expr] โ€” The shell exits either with the value of the specified expr (an expression, as described under โ€œExpressionsโ€) or, without expr, with the value 0.

fg [%job ...] โ€” Brings the specified jobs (or, without arguments, the current job) into the foreground, continuing each if it is stopped. job may be a number, a string, โ€˜โ€™, โ€˜%โ€™, โ€˜+โ€™, or โ€˜-โ€™ as described under โ€œJobsโ€. See also the run-fg-editor editor command.

filetest -op file ... (+) โ€” Applies op (which is a file inquiry operator as described under โ€œFile inquiry operatorsโ€) to each file and returns the results as a space-separated list. ๐ŸŽ€

foreach โ€” Successively sets the variable name to each member of wordlist and executes the sequence of commands between this command and the matching end.

foreach name (wordlist)
...
end

Both foreach and end must appear alone on separate lines. The builtin command continue may be used to continue the loop prematurely and the builtin 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. ๐Ÿซถ

getspath (+) โ€” Prints the system execution path. (TCF only)

getxvers (+) โ€” Prints the experimental version prefix. (TCF only)

glob word ... โ€” Like echo, but the -n parameter is not recognized and words are delimited by null characters in the output. Useful for programs which wish to use the shell to filename expand a list of words. ๐Ÿฆ‹

goto word โ€” word is filename and command-substituted to yield a string of the form โ€˜labelโ€™. The shell rewinds its input as much as possible, searches for a line of the form

label:

possibly preceded by blanks or tabs, and continues execution after that line. โœจ

hashstat โ€” Prints a statistics line indicating how effective the internal hash table has been at locating commands (and avoiding exec's). An exec is attempted for each component of the path where the hash function indicates a possible hit, and in each component which does not begin with a โ€˜/โ€™.

On machines without vfork(2), prints only the number and size of hash buckets. ๐Ÿ’…

history โ€” The forms are:

history [-hTr] [n]
history -S|-L|-M [filename] (+)
history -c (+)

The first form prints the history event list. If n is given only the n most recent events are printed or saved. With -h, the history list is printed without leading numbers. If -T is specified, timestamps are printed also in comment form. This can be used to produce files suitable for loading with

history -L

or

source -h

With -r, the order of printing is most recent first rather than oldest first.

The second form with -S saves the history list to filename. If the first word of the savehist shell variable is set to a number, at most that many lines are saved. If the second word of savehist 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. (+) Merging is intended for an environment like the X Window System with several shells in simultaneous use. If the second word of savehist is merge and the third word is set to lock, the history file update will be serialized with other shell sessions that would possibly like to merge history at exactly the same time.

The second form with -L appends filename (which is presumably a history list saved by the -S option or the savehist mechanism) to the history list. -M is like -L, but the contents of filename are merged into the history list and sorted by timestamp. In either case, histfile is used if filename is not given and ~/.history is used if histfile is unset.

Note that

history -L

is exactly like

source -h

except that it does not require a filename.

Note that login shells do the equivalent of

history -L

on startup and, if savehist is set,

history -S

before exiting. Because only ~/.tcshrc is normally sourced before ~/.history, histfile should be set in ~/.tcshrc rather than ~/.login.

If histlit is set, the first and second forms print and save the literal (unexpanded) form of the history list.

The third form clears the history list. ๐Ÿ’œ

hup [command] (+) โ€” With command, runs command such that it will exit on a hangup signal and arranges for the shell to send it a hangup signal when the shell exits. Note that commands may set their own response to hangups, overriding hup. Without an argument, causes the non-interactive shell only to exit on a hangup for the remainder of the script. See also โ€œSignal handlingโ€ and the nohup builtin command. ๐ŸŽ€

if (expr) command โ€” If expr (an expression, as described under โ€œExpressionsโ€) evaluates true, then command is executed. Variable substitution on command happens early, at the same time it does for the rest of the if command. command must be a simple command, not an alias, a pipeline, a command list or a parenthesized command list, but it may have arguments. Input/output redirection occurs even if expr is false and command is thus not executed; this is a bug. ๐Ÿ˜ญ

if (expr) then ... else if (expr2) then ... else ... endif โ€” The form is:

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, etc. Any number of else if pairs are possible; only one endif is needed. The else part is likewise 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.) โœจ

inlib shared-library ... (+) โ€” Adds each shared-library to the current environment. There is no way to remove a shared library. (Domain/OS only)

jobs [-l] / jobs -Z [title] (+) โ€” The first form lists the active jobs. With -l, lists process IDs in addition to the normal information. On TCF systems, prints the site on which each job is executing.

The second form with the -Z option sets the process title to title using setproctitle(3) where available. If no title is provided, the process title will be cleared. ๐Ÿ’…

kill -l / kill [-s signal] %job|pid ... โ€” The first form lists the signal names.

The second form sends the specified signal (or, if none is given, the TERM (terminate) signal) to the specified jobs or processes. job may be a number, a string, โ€˜โ€™, โ€˜%โ€™, โ€˜+โ€™, or โ€˜-โ€™ as described under โ€œJobsโ€. Signals are either given by number or by name (as given in /usr/include/signal.h, stripped of the prefix SIG).

There is no default job; entering just

kill

does not send a signal to the current job. If the signal being sent is TERM (terminate) or HUP (hangup), then the job or process is sent a CONT (continue) signal as well. ๐Ÿ’€

limit [-h] [resource [maximum-use]] โ€” Limits the consumption by the current process and each process it creates to not individually exceed maximum-use on the specified resource.

If no maximum-use is given, then the current limit for resource is printed.

If no resource is given, then all limitations are given.

If the -h flag is given, the hard limits are used instead of the current limits. The hard limits impose a ceiling on the values of the current limits. Only the super-user may raise the hard limits, but a user may lower or raise the current limits within the legal range.

Controllable resource types currently include (if supported by the OS): ๐Ÿซถ

  • concurrency โ€” Maximum number of threads for this process.
  • coredumpsize โ€” Size of the largest core dump that will be created.
  • cputime โ€” Maximum number of cpu-seconds to be used by each process.
  • datasize โ€” Maximum growth of the data+stack region via sbrk(2) beyond the end of the program text.
  • descriptors or openfiles โ€” Maximum number of open files for this process.
  • filesize โ€” Largest single file which can be created.
  • heapsize โ€” Maximum amount of memory a process may allocate per brk(2) system call.
  • kqueues โ€” the max number of kqueues this process can have allocated.
  • maxlocks โ€” biggest number of locks for this user.
  • maxmessage โ€” biggest number of bytes in POSIX mqueues for this user.
  • maxnice โ€” the highest nice priority this user is allowed to raise, mapped from [19...-20] to [0...39].
  • maxproc โ€” max simultaneous processes for this user id.
  • maxrtprio โ€” max realtime priority for this user.
  • maxrttime โ€” timeout for RT tasks, in microseconds, for this user.
  • maxsignal โ€” max number of pending signals for this user.
  • maxthread โ€” max simultaneous threads (lightweight processes) for this user id.
  • memorylocked โ€” biggest size a process may lock into memory using mlock(2).
  • memoryuse โ€” max physical memory a process may have allocated to it at any given time.
  • posixlocks โ€” max number of POSIX advisory locks for this user.
  • pseudoterminals โ€” max number of pseudo-terminals for this user.
  • sbsize โ€” max size of socket buffer usage for this user.
  • stacksize โ€” max size of the automatically-extended stack region.
  • swapsize โ€” max swap space reserved or used for this user.
  • threads โ€” max number of threads for this process.
  • vmemoryuse โ€” max virtual memory a process may have allocated at any given time (that's the address space, bestie).

maximum-use can be a floating point or integer number, then a scale factor. For every limit except cputime, the default scale is k or kilobytes (1024 bytes) โ€” and you can also use m or megabytes (1048576 bytes), or g or gigabytes (1073741824 bytes). For cputime the default scaling is seconds, but m for minutes or h for hours works too, or a time shaped like mm:ss for minutes and seconds. โœจ

If maximum-use is unlimited, the limit on that resource is justโ€ฆ gone (same energy as the unlimit builtin, fr).

For both resource names and scale factors, unambiguous prefixes of the names are enough. iykyk ๐Ÿ’…


๐ŸŽ€ the builtins, continued ๐ŸŽ€

  • log (+) โ€” prints the watch shell variable and reports on every user listed in watch who is logged in, no matter when they last logged in. Peep watchlog too.
  • login โ€” terminates a login shell and replaces it with an instance of /bin/login. It's one way to log off, and it's here for sh(1) compatibility.
  • logout โ€” terminates a login shell. Genuinely a lifesaver if ignoreeof is set.
  • ls-F [-switch ...] [file ...] (+) โ€” lists files like
ls -F

but so much faster, no cap.

ls-F tags each type of special file in the listing with a special character suffix:

  • / โ€” directory.
  • * โ€” executable.
  • # โ€” block device.
  • % โ€” character device.
  • | โ€” named pipe (systems with named pipes only).
  • = โ€” socket (systems with sockets only).
  • @ โ€” symbolic link (systems with symbolic links only).
  • + โ€” hidden directory (AIX only) or context dependent (HP/UX only).
  • : โ€” network special (HP/UX only).

If the listlinks shell variable is set, symbolic links get identified in way more detail (obviously only on systems that have them):

  • @ โ€” symbolic link to a non-directory.
  • > โ€” symbolic link to a directory.
  • & โ€” orphaned (broken) symbolic link.

Heads up though: listlinks also slows ls-F down and causes partitions holding files pointed to by symbolic links to be mounted. ๐Ÿ’€

If the listflags shell variable is set to x, a, or A, or any combo of those (like xA), they're used as flags to ls-F, making it act like

ls -xF
ls -Fa
ls -FA

or a combination, for example

ls -FxA

On machines where

ls -C

isn't the default, ls-F acts like

ls -CF

unless listflags contains an x, and then it acts like

ls -xF

ls-F passes its arguments to ls(1) if you give it any switches, so

alias ls ls-F

generally does the right thing. ๐Ÿซถ

The ls-F builtin can list files using different colors depending on file type or extension. See the color shell variable and the CLICOLOR_FORCE, LSCOLORS, and LS_COLORS environment variables. ๐ŸŒˆ

  • migrate [-site] pid|%jobid ... (+)
  • migrate -site (+)

First form migrates the process or job to the site specified, or to the default site determined by the system path. (TCF only)

Second form is equivalent to

migrate -site $$

in that it migrates the current process to the specified site. Word of warning: migrating the shell itself can cause unexpected behavior, because the shell does not like to lose its tty. ๐Ÿ˜ญ (TCF only)

  • newgrp [-] [group] (+) โ€” equivalent to
exec newgrp

as per newgrp(1). Only available if the shell was compiled that way; check the version shell variable.

  • nice [+number] [command] โ€” bumps the scheduling priority for the shell up by number, or by 4 if you don't give one. With command, it runs command at the appropriate priority. The bigger the number, the less cpu the process gets. The super-user can decrement the priority by using
nice -number ...

command is always executed in a sub-shell, and the restrictions placed on commands in simple if statements apply.

  • nohup [command] โ€” with command, runs it so it ignores hangup signals. Note that commands may set their own response to hangups, which overrides nohup. ๐Ÿ™ˆ

Without an argument, it makes the non-interactive shell only ignore hangups for the rest of the script. See also โ€œSignal handlingโ€ and the hup builtin command.

  • notify [%job ...] โ€” makes the shell notify you asynchronously when the status of any of the specified jobs changes (or, with no %job, the current job), instead of waiting until the next prompt like usual. job can be a number, a string, '', %, +, or -, as described under โ€œJobsโ€. See also the notify shell variable.
  • onintr [-|label] โ€” controls what the shell does on interrupts. No arguments: restores the default action on interrupts, which is to terminate shell scripts or go back to the terminal command input level.

With -, all interrupts are ignored.

With label, the shell executes a

goto label

when an interrupt is received, or when a child process terminates because it was interrupted.

onintr is ignored if the shell is running detached and in system startup files (see โ€œFILESโ€), where interrupts are disabled anyway.

  • popd [-p] [-l] [-n|-v] [+n] โ€” with no arguments, pops the directory stack and returns to the new top directory.

With a number +n, it discards the nth entry in the stack.

And finally, every form of popd prints the final directory stack, just like dirs. Set the pushdsilent shell variable to stop that, or pass the -p flag to override pushdsilent. The -l, -n, and -v flags have the same effect on popd as they do on dirs. (+)

  • printenv [name] (+) โ€” prints the names and values of all environment variables, or, with name, the value of the environment variable name.
  • pushd [-p] [-l] [-n|-v] [name|+n] โ€” with no arguments, exchanges the top two elements of the directory stack. If pushdtohome is set, pushd with no arguments acts as
pushd ~

just like cd. (+)

With name, it pushes the current working directory onto the directory stack and changes to name. If name is -, it's interpreted as the previous working directory (see โ€œFilename substitutionโ€). (+) If dunique is set, pushd removes any instances of name from the stack before pushing it on. (+)

With a number +n, it rotates the nth element of the directory stack around to be the top element and changes to it. If dextract is set, though,

pushd +n

extracts the nth directory, pushes it onto the top of the stack and changes to it. (+)

And finally, every form of pushd prints the final directory stack, just like dirs. Set pushdsilent to stop that, or give the -p flag to override pushdsilent. The -l, -n, and -v flags have the same effect on pushd as on dirs. (+)

  • rehash โ€” causes the internal hash table of the contents of the directories in the path variable to be recomputed. You need this if autorehash isn't set and new commands get added to directories in path while you're logged in. With autorehash, a new command gets found automatically โ€” except in that special case where another command with the same name, living in a different directory, already exists in the hash table. It also flushes the cache of home directories built by tilde expansion. ๐Ÿฆ‹

repeat ๐Ÿ’…

repeat count command

Runs command exactly count times. Lowkey the rules that apply to command here are the same ones as for the command in the one-line if statement from earlier, so no funny business. And bestie, listen: I/O redirections happen exactly once, even when count is 0. That's the tea. ๐Ÿซ–


rootnode ๐ŸŽ€

rootnode //nodename (+)

Swaps the rootnode over to //nodename, so that every time you type / it secretly means //nodename. Sneaky little thing. (Domain/OS only)


sched โฐ

sched (+)
sched [+]hh:mm command (+)
sched -n (+)

Three whole moods, okay? Let's go.

Form one prints out the scheduled-event list. And if you're feeling fancy, the sched shell variable can be set to control the format that list prints in. Customize away. โœจ

Form two adds a command to the scheduled-event list. For example:

> sched 11:00 echo It\'s eleven o\'clock.

makes the shell echo

It's eleven o'clock.

at 11 AM. Iconic behaviour, honestly.

The time can also be in 12-hour AM/PM format:

> sched 5pm set prompt='[%h] It\'s after 5; go home: >'

or it can be relative to right now:

> sched +2:15 /usr/lib/uucp/uucico -r1 -sother
๐Ÿšจ Heads up: a relative time specification is not allowed to use AM/PM format. Periodt.

Form three deletes item n from the event list:

> sched
1  Wed Apr  4 15:42  /usr/lib/uucp/uucico -r1 -sother
2  Wed Apr  4 17:00  set prompt=[%h] It's after 5; go home: >
> sched -2
> sched
1  Wed Apr  4 15:42  /usr/lib/uucp/uucico -r1 -sother

Now the deets on when stuff actually runs, because this is where people get confused ๐Ÿ˜ญ. A command sitting in the scheduled-event list gets executed just before the first prompt is printed after the time it was scheduled for. So yeah โ€” it is possible to completely miss the exact time a command was supposed to run, but an overdue command will still execute at the next prompt. Better late than never, I guess. ๐Ÿ’€

A command that comes due while the shell is just sitting there waiting for user input? It runs immediately, instantly, no waiting. However โ€” and this is the important bit โ€” the normal operation of a command that's already running will not be interrupted just so a scheduled-event list element can get its moment. Don't be rude to the running command.

This whole mechanism is similar to, but genuinely not the same as, the at(1) command on some Unix systems. Its major disadvantage is that it may not run a command at exactly the specified time. Its major advantage is that because sched runs directly from the shell, it has access to shell variables and other structures. Which is honestly a whole superpower: it gives you a mechanism for changing your working environment based on the time of day. Main character scheduling. ๐Ÿ‘‘


set ๐ŸŒธ

set
set name ...
set name=word ...
set [-r] [-f|-l] name=(wordlist) ... (+)
set name[index]=word ...
set -r (+)
set -r name ... (+)
set -r name=word ... (+)

Eight forms, bestie. Eight. Let's count them like a responsible queen. ๐Ÿ‘‘

First form: prints the value of all shell variables. Any variable holding more than a single word gets printed as a parenthesized word list.

Second form: sets name to the null string.

Third form: sets name to the single word.

Fourth form: sets name to the list of words in wordlist.

In all of these cases the value is command and filename expanded. If -r is specified, the value is set read-only. If -f or -l are specified, set only keeps unique words, preserving their order โ€” -f prefers the first occurrence of a word, and -l the last. Pick your fighter. ๐ŸฅŠ

Fifth form: sets the index'th component of name to word โ€” and that component has to already exist, no inventing new ones.

Sixth form: lists only the names of all shell variables that are read-only.

Seventh form: makes name read-only, whether or not it actually has a value.

Eighth form: same as the third form, but makes name read-only at the same time. Two birds, one stone.

You can repeat these arguments to set and/or make read-only multiple variables in a single set command. Cute. But note: variable expansion happens for all arguments before any setting occurs. Timing matters, bestie. โณ Also note that = can be adjacent to both name and word, or separated from both by whitespace, but it cannot be adjacent to only one or the other. Pick a lane. And go see the unset builtin command too.


setenv ๐Ÿฆ‹

setenv [name [value]]

With no arguments at all? Prints the names and values of all environment variables. Enjoy the wall of text. ๐Ÿ“œ

With name? Sets the environment variable name to value โ€” or, if you don't give a value, to the null string. Simple as that.


setpath ๐ŸŒˆ

setpath path (+)

Equivalent to setpath(1). (Mach only)


setspath ๐Ÿงš

setspath LOCAL|site|cpu ... (+)

Sets the system execution path. (TCF only)


settc โญ

settc cap value (+)

Tells the shell to believe that the terminal capability cap (as defined in termcap(5)) has the value value. And ngl? No sanity checking is done. None. Zero. It just trusts you. ๐Ÿ™ˆ

Concept terminal users may have to run

settc xn no

to get proper wrapping at the rightmost column. The more you know. ๐Ÿ’ซ


setty ๐Ÿ’…

setty [-d|-q|-x] [-a] [[+|-]mode] (+)

This one controls which tty modes (see โ€œTerminal management (+)โ€) the shell does not allow to change. Bossy, but make it fashion.

-d, -q, or -x tell setty to act on the โ€˜editโ€™, โ€˜quoteโ€™, or โ€˜executeโ€™ set of tty modes respectively; if you give none of -d, -q, or -x, then โ€˜executeโ€™ is used. Default behaviour, love to see it.

With no other arguments, setty lists the modes in the chosen set which are fixed on (+mode) or off (-mode). And the available modes โ€” and therefore the display โ€” vary from system to system, so don't @ me if yours looks different. ๐ŸŒ

With -a, it lists all tty modes in the chosen set, whether or not they're fixed.

With +mode, -mode, or mode, it fixes mode on or off, or removes control from mode in the chosen set. For example:

setty +echok echoe

fixes โ€˜echokโ€™ mode on and allows commands to turn โ€˜echoeโ€™ mode on or off โ€” both of those when the shell is executing commands. Locked in. ๐Ÿ”’


setxvers ๐ŸŽ€

setxvers [string] (+)

Sets the experimental version prefix to string, or removes it entirely if you omit string. (TCF only)


shift ๐ŸŒ€

shift [variable]

No arguments? It discards argv[1] and shifts all the members of argv to the left. Everybody scoot over. It is an error for argv to not be set, or to have fewer than one word as its value. ๐Ÿ˜ญ

With variable, it performs that exact same little shuffle on variable instead.


source ๐Ÿ“–

source [-h] name [args ...]

The shell reads and executes commands from name. Those commands do not get placed on the history list. (Sneaky.) If you give any args, they get placed in argv. (+) Also, source commands may be nested โ€” but if they're nested too deeply, the shell may run out of file descriptors. ๐Ÿ’€ And an error in a source at any level terminates all nested source commands. Whole tower comes down, bestie.

With -h, the commands are placed on the history list instead of being executed โ€” much like

history -L

stop โœ‹

stop %job|pid ...

Stops the specified jobs or processes that are executing in the background. The job may be a number, a string, โ€˜โ€™, โ€˜%โ€™, โ€˜+โ€™, or โ€˜-โ€™, as described under โ€œJobsโ€.

โš ๏ธ There is no default job โ€” so just typing
stop
does not stop the current job. You have to actually say which one. No vibes-based stopping.

suspend ๐Ÿ˜ด

suspend

Causes the shell to stop dead in its tracks, much as if it had been sent a stop signal with ^Z. Most often used to stop shells started by su(1). Go to sleep, queen. ๐Ÿ›Œ


switch ๐Ÿ”€

switch (string)
case str1:
    ...
    breaksw
...
default:
    ...
    breaksw
endsw

Each case label gets successively matched against the specified string, which is first command and filename expanded. The file metacharacters โ€˜*โ€™, โ€˜?โ€™, and โ€˜[...]โ€™ may be used in the case labels, which are variable expanded. Fancy. โœจ

If none of the labels match before a default label is found, then execution begins after the default label. Each case label and the default label must appear at the beginning of a line. Rules are rules.

The command breaksw causes execution to continue after the endsw. Otherwise, control may fall through case labels and default labels exactly like in C. If no label matches and there's no default, execution just continues after the endsw. No drama. ๐Ÿ’…


telltc ๐Ÿ–ฅ๏ธ

telltc (+)

Lists the values of all terminal capabilities (see termcap(5)). The full receipts. ๐Ÿงพ


termname ๐Ÿท๏ธ

termname [termtype] (+)

Tests whether termtype (or the current value of TERM, if you don't pass a termtype) actually has an entry in the host's termcap(5) or terminfo(5) database. It prints the terminal type to stdout and returns 0 if an entry is present โ€” otherwise it returns 1. Simple pass/fail energy. โœ…


time โฑ๏ธ

time [command]

Executes command โ€” and psst, it must be a simple command. Not an alias, not a pipeline, not a command list, not a parenthesized command list. Nothing fancy โ€” and prints a time summary as described under the time variable. If necessary, an extra shell gets created just to print the time statistic when the command completes. Dedication. ๐Ÿซก

Without a command, it prints a time summary for the current shell and its children.


umask ๐ŸŽญ

umask [value]

Sets the file creation mask to value, which โ€” important โ€” is given in octal. Common values for the mask are 002, giving all access to the group and read and execute access to others, and 022, giving read and execute access to the group and others.

Without a value, it prints the current file creation mask.


unalias ๐Ÿšซ

unalias pattern

Removes all aliases whose names match pattern. So like:

unalias *

removes all aliases. Poof. And it is not an error for nothing to be unaliased โ€” so don't stress if it comes up empty. ๐Ÿซถ


uncomplete ๐Ÿงน

uncomplete pattern (+)

Removes all completions whose names match pattern. So:

uncomplete *

removes all completions. And again โ€” it is not an error for nothing to be uncompleted. Clean slate, bestie. ๐ŸŒธ


unhash ๐Ÿ”“

unhash

Disables use of the internal hash table to speed up the location of executed programs. Bye-bye shortcut, hello searching. ๐Ÿข


universe ๐ŸŒŒ

universe universe (+)

Sets the universe to universe. (Masscomp/RTU only) Yes, that's the whole thing. Universe-ception. ๐Ÿช


unlimit โ™พ๏ธ

unlimit [-hf] [resource]

Removes the limitation on resource โ€” or, if you don't specify a resource, removes all resource limitations. Freedom. ๐Ÿ•Š๏ธ

With -h, the corresponding hard limits are removed. Only the super-user may do this, so check your privileges before you get ambitious. ๐Ÿ‘‘

๐Ÿšจ Note that unlimit may not exit successful, since most systems do not allow descriptors to be unlimited. It tried its best.

With -f, errors are ignored. Ignorance is bliss. ๐Ÿ™ˆ


unset ๐Ÿ—‘๏ธ

unset pattern

Removes all variables whose names match pattern โ€” unless they're read-only, in which case, no. So:

unset *

removes all variables unless they are read-only. And nglโ€ฆ this is a bad idea. Do not do this. I'm serious. ๐Ÿ’€๐Ÿ˜ญ

It is not an error for nothing to be unset, though. So at least there's that. ๐Ÿซถ

unsetenv pattern

Nukes every single environment variable whose name matches pattern. So like:

unsetenv *

yeets all your environment variables into the sun. Do not do this. It's giving chaos. ๐Ÿ™ˆ

And ngl, if nothing matches? Not an error. The shell just shrugs and moves on. No drama. ๐Ÿ’…

ver [systype [command]] (+)

Bare ver, no args? It prints SYSTYPE. That's it, that's the whole vibe.

Give it systype and it sets SYSTYPE to systype.

Give it both systype and command and it executes command under systype.

systype can be โ€˜bsd4.3โ€™ or โ€˜sys5.3โ€™.

Domain/OS only, bestie โ€” if you're not on it, this one's not for you ๐Ÿ’–

wait

The shell waits for all background jobs to finish. All of them. Like a bestie holding the group's bags at the mall. ๐Ÿซถ

If the shell is interactive though, an interrupt will disrupt the wait, and then the shell prints out the names and job numbers of all the outstanding jobs โ€” so you can see exactly who's still out there being slow. ๐Ÿ˜ญ

warp universe (+)

Sets the universe to universe.

Convex/OS only! โœจ

watchlog (+)

An alternate name for the log builtin command. Only available if the shell was compiled with it โ€” peep the version shell variable to check. ๐Ÿ‘‘

where command (+)

Reports all known instances of command โ€” aliases, builtins, and executables in path, the whole roster. It's giving "who's who in the command world." ๐Ÿ’…

which command (+)

Shows you the command that will actually be executed by the shell after substitutions, path searching, etc. The builtin is basically which(1)'s cooler sibling โ€” but it correctly reports tcsh aliases and builtins, and it's 10 to 100 times faster. Periodt. ๐Ÿ”ฅ

Also see the which-command editor command. โœจ

while (expr) โ€ฆ end

while (expr)
...
end

Runs the commands between the while and the matching end while expr โ€” an expression, as described under "Expressions" โ€” evaluates non-zero. Yes, that's literally the while-loop of your dreams. ๐ŸŒ€

while and end must appear alone on their input lines. No sneaking extra stuff on the same line, babe.

break and continue can be used to terminate or continue the loop prematurely, if you change your mind mid-loop (valid).

And if the input is a terminal, you get prompted the first time through the loop, same as with foreach. ๐ŸŒธ


๐ŸŽ€ Special aliases (+) ๐ŸŽ€

If set, each of these aliases executes automatically at the indicated time. They are all initially undefined โ€” so nothing happens until you make it happen. ๐Ÿ˜Œ

The supported special aliases are:

beepcmd

Runs when the shell wants to ring the terminal bell. Ding ding. ๐Ÿ””

cwdcmd

Runs after every change of working directory. Iconic behaviour honestly.

For example, if you're working on an X window system using xterm(1) and a re-parenting window manager that supports title bars such as twm(1), and you do

> alias cwdcmd  'echo -n "^[]2;${HOST}:$cwd ^G"'

then the shell will change the title of the running xterm(1) to be the name of the host, a โ€˜:โ€™, and the full current working directory. Slay. ๐ŸชŸ

A fancier way to do that is

> alias cwdcmd 'echo -n "^[]2;${HOST}:$cwd^G^[]1;${HOST}^G"'

This puts the hostname and working directory on the title bar but only the hostname in the icon manager menu. Fancy fancy. ๐Ÿ‘‘

โš ๏ธ Heads up bestie: putting a cd, pushd, or popd in cwdcmd may cause an infinite loop. And it is the author's opinion that anyone doing so will get what they deserve. ๐Ÿ’€ No cap.

jobcmd

Runs before each command gets executed, or when the command changes state. Similar to postcmd, but it does not print builtins.

> alias jobcmd  'echo -n "^[]2\;\!#:q^G"'

Then executing

vi foo.c

will put the command string in the xterm title bar. Vibe check: passed. โœ…

helpcommand

Invoked by the run-help editor command. The command name for which help is sought is passed as the sole argument. For example, if you do

> alias helpcommand '\!:1 --help'

then the help display of the command itself gets invoked, using the GNU help calling convention. ๐Ÿงš

Currently there's no easy way to account for the various calling conventions (e.g., the customary Unix โ€˜-hโ€™), except by using a table of many commands. It's giving "we tried our best." ๐Ÿ˜ญ

periodic

Runs every tperiod minutes. This is a super convenient way to check on common but infrequent changes like new mail. ๐Ÿ’Œ

So if you do

> set tperiod = 30
> alias periodic checknews

then the checknews(1) program runs every 30 minutes. Love that for you.

If periodic is set but tperiod is unset or set to 0, periodic behaves like precmd.

precmd

Runs just before each prompt is printed. Every prompt. Fresh. New.

For example, if you do

> alias precmd date

then date(1) 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. Bestie. Please. Be normal about it. ๐Ÿ™ˆ

postcmd

Runs before each command gets executed.

> alias postcmd  'echo -n "^[]2\;\!#:q^G"'

Then executing

vi foo.c

will put the command string in the xterm title bar. ๐ŸŽ€

shell

Specifies the interpreter for executable scripts which don't themselves specify an interpreter. The first word should be a full path name to the desired interpreter (e.g., โ€˜/bin/cshโ€™ or โ€˜/usr/local/bin/tcshโ€™). ๐Ÿ’ป


๐ŸŒˆ Special shell variables ๐ŸŒˆ

The variables described in this section have special meaning to the shell. They're not like other variables. They're the main characters. ๐Ÿ‘‘

The shell sets addsuffix, argv, autologout, csubstnonl, command, echo_style, edit, gid, group, home, loginsh, oid, 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 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. Two-way street, literally. ๐Ÿ”„

Quick note: even though cwd and PWD have identical meanings, they are not synchronized this way. Also, the shell automatically converts between the different formats of path and PATH. Iykyk โœจ

The supported special shell variables are:

addsuffix (+)

If set, filename completion adds โ€˜/โ€™ to the end of directories and a space to the end of normal files when they're matched exactly. Set by default. ๐ŸŽ€

afsuser (+)

If set, autologout's autolock feature uses its value instead of the local username for kerberos authentication.

ampm (+)

If set, all times are shown in 12-hour AM/PM format. Clock girlies rise. ๐Ÿ•

anyerror (+)

This variable selects what gets propagated to the value of the status variable. For more info, see the description of the status variable below.

argv

The arguments to the shell. Positional parameters are taken from argv, i.e., โ€˜$1โ€™ is replaced by โ€˜$argv[1]โ€™, etc. Set by default, but usually empty in interactive shells.

autocorrect (+)

If set, the spell-word editor command gets invoked automatically before each completion attempt. Autocorrect but make it Unix. โœจ

autoexpand (+)

If set, the expand-history editor command gets invoked automatically before each completion attempt.

If this is set to โ€˜onlyhistoryโ€™, then only history gets expanded and a second completion will expand filenames. Two-step process, very chic. ๐Ÿ’…

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 (+)

The first word is the number of minutes of inactivity before automatic logout. The optional second word is the number of minutes of inactivity before automatic locking. ๐Ÿ˜ด

When the shell automatically logs out, it prints

auto-logout

sets the variable logout to โ€˜automaticโ€™ and exits.

When the shell automatically locks, you're required to enter your password to keep working. Five incorrect attempts results in automatic logout. Don't test it. ๐Ÿ’€

Set to โ€˜60โ€™ (automatic logout after 60 minutes, and no locking) by default in login and superuser shells โ€” but not if the shell thinks it's running under a window system (i.e., the DISPLAY environment variable is set), the tty is a pseudo-tty (pty), or the shell was not compiled that way (see the version shell variable).

Unset autologout or set it to โ€˜0โ€™ to disable automatic logout. Also see the afsuser and logout shell variables. ๐Ÿซถ

autorehash (+)

If set, the internal hash table of the contents of the directories in the path variable will be recomputed if a command is not found in the hash table.

Plus, the list of available commands gets rebuilt for each command completion or spelling correction attempt if set to โ€˜completeโ€™ or โ€˜correctโ€™ respectively; if set to โ€˜alwaysโ€™, this gets done for both cases. Always be caching. โšก

backslash_quote (+)

If set, backslashes (\) always quote \, ', and ". This may make complex quoting tasks easier, but it can cause syntax errors in csh(1) scripts. โš ๏ธ

catalog

The file name of the message catalog. If set, tcsh uses tcsh.${catalog} as a message catalog instead of the default tcsh.

cdpath

A list of directories in which cd should search for subdirectories if they aren't found in the current directory. ๐Ÿšช

cdtohome (+)

If not set, cd requires a directory name, and will not go to the home directory if it's omitted. This is set by default. ๐Ÿ 

color

If set, it enables color display for the builtin ls-F and passes --color=auto to ls(1) (or --color=always if CLICOLOR_FORCE is set). ๐ŸŒˆ

Alternatively, it can be set to only โ€˜ls-Fโ€™ or only โ€˜lsโ€™ to enable color for a specific command. Setting it to nothing is equivalent to setting it to โ€˜(ls-F ls)โ€™.

Color is disabled if the output is not directed to a terminal, unless CLICOLOR_FORCE is set.

colorcat

If set, it enables the color escape sequence for NLS message files, and displays colorful NLS messages. ๐ŸŒธ

command (+)

If set, the command which was passed to the shell with the -c flag.

compat_expr (+)

If set, the shell will evaluate expressions right to left, like the original csh(1). Retro vibes, chaotic energy. ๐Ÿ’€

complete (+)

If set to โ€˜igncaseโ€™, the completion becomes case insensitive.

If it's set to โ€˜enhanceโ€™, completion is like lowercase girlie mode: it ignores case and treats hyphens and underscores as the same thing, plus it treats periods, hyphens and underscores (โ€˜.โ€™, โ€˜-โ€™, and โ€˜_โ€™) as word separators. Casual vibes only ๐Ÿ’…

If it's set to โ€˜Enhanceโ€™ (capital E, main character energy), completion matches uppercase and underscore characters explicitly, and matches lowercase and hyphens in a case-insensitive way; it'll treat periods, hyphens and underscores as word separators too.

  • continue (+) Give it a list of commands and the shell will continue those listed commands instead of starting a whole new one. No starting over, we stay on the ride ๐ŸŽข
  • continue_args (+) Same as continue bestie, but the shell executes this instead:
echo `pwd` $argv > ~/.<cmd>_pause; %<cmd>
  • correct (+)
    • Set it to โ€˜cmdโ€™ and commands get automatically spelling-corrected โœจ
    • Set it to โ€˜completeโ€™ and commands get automatically completed ๐Ÿ’–
    • Set it to โ€˜allโ€™ and the entire command line gets corrected. the whole thing. iconic.
  • csubstnonl (+) If set, newlines and carriage returns inside command substitution get swapped out for spaces. It's set by default, so this is literally the norm ๐Ÿซถ
  • cwd The full pathname of the current directory. Peep the dirstack and owd shell variables too, they're the besties of this one ๐Ÿฆ‹
  • dextract (+) If set, then
pushd +n

extracts the nth directory from the directory stack instead of rotating it up to the top. pull it out, don't shuffle it around ๐Ÿ’…

  • dirsfile (+) The default location where
dirs -S

and

dirs -L

go looking for a history file. If it's unset, ~/.cshdirs is used. And listen โ€” because only ~/.tcshrc is normally sourced before ~/.cshdirs, you should set dirsfile in ~/.tcshrc rather than ~/.login. order matters, ok?? ๐Ÿ˜ญ

  • dirstack (+) An array of all the directories on the directory stack. โ€˜$dirstack[1]โ€™ is the current working directory, โ€˜$dirstack[2]โ€™ is the first directory on the stack, etc. Heads up tho: the current working directory is โ€˜$dirstack[1]โ€™ but it's โ€˜=0โ€™ in directory stack substitutions and stuff. You can change the stack arbitrarily by setting dirstack, but the first element (the current working directory) is always correct. Also see the cwd and owd shell variables ๐ŸŽ€
  • dspmbyte (+) This one only does anything if โ€˜dspmโ€™ is listed as part of the version shell variable. Gatekept fr.
    • Set it to โ€˜eucโ€™ and it enables display and editing of EUC-kanji (Japanese) code ๐Ÿ‡ฏ๐Ÿ‡ต
    • Set it to โ€˜sjisโ€™ and it enables display and editing of Shift-JIS (Japanese) code
    • Set it to โ€˜big5โ€™ and it enables display and editing of Big5 (Chinese) code
    • Set it to โ€˜utf8โ€™ and it enables display and editing of Utf8 (Unicode) code ๐ŸŒˆ

If you set it to exactly 256 characters in the following format, it enables display and editing of your very own original multi-byte code format:

> set dspmbyte = NNN...[250 characters]...NNN

Each character N in that 256-character value corresponds (left to right) to the ASCII codes 0x00, 0x01, 0x02, ..., 0xfd, 0xfe, 0xff at the same index. Every character gets set to a number โ€” 0, 1, 2 or 3 โ€” with these meanings:

  • 0 โ€” not used for multi-byte characters
  • 1 โ€” used for the first byte of a multi-byte character
  • 2 โ€” used for the second byte of a multi-byte character
  • 3 โ€” used for both the first byte and second byte of a multi-byte character

So like, for example, if it's set to 256 characters starting with โ€˜001322โ€™, the value gets interpreted as:

  • character 0 / ASCII 0x00 โ€” not used
  • character 0 / ASCII 0x01 โ€” not used
  • character 1 / ASCII 0x02 โ€” first byte
  • character 3 / ASCII 0x03 โ€” first byte and second byte
  • character 2 / ASCII 0x04 โ€” second byte
  • character 2 / ASCII 0x05 โ€” second byte

Now the tea โ˜•: the GNU coreutils version of ls(1) cannot display multi-byte filenames without the -N (--literal) option. If that's your version, set the second word of dspmbyte to โ€˜lsโ€™. If you don't, then something like

ls-F -l

cannot display multi-byte filenames. it just can't ๐Ÿ˜ญ

Note that this variable can only be used if KANJI and DSPMBYTE have been defined at compile time. no compile-time define, no feature. sorry babe.
  • dunique (+) If set, pushd removes any instances of name from the stack before pushing it onto the stack. no duplicates allowed in this house ๐Ÿšซ
  • echo If set, each command with its arguments is echoed just before it's executed. For non-builtin commands, all expansions happen before echoing. Builtin commands get echoed before command and filename substitution, because those substitutions are done selectively. Set by the -x command line option. very "narrating my own life" of it ๐Ÿ’€
  • echo_style (+) The style of the echo builtin. May be set to:
    • bsd โ€” don't echo a newline if the first argument is -n; the default for csh(1)
    • sysv โ€” recognize backslashed escape sequences in echo strings
    • both โ€” recognize both the -n flag and backslashed escape sequences; the default for tcsh
    • none โ€” recognize neither. feral. but okay.

It's set by default to the local system default. The BSD and System V options are described in the echo(1) man pages on the appropriate systems ๐Ÿ“–

  • edit (+) If set, the command-line editor is used. It's set by default in interactive shells, as it should be ๐Ÿ’…
  • editors (+) A list of command names for the run-fg-editor editor command to match against. If it's not set, the EDITOR (โ€˜edโ€™ if unset) and VISUAL (โ€˜viโ€™ if unset) environment variables get used instead.
  • ellipsis (+) If set, the โ€˜%cโ€™, โ€˜%.โ€™, and โ€˜%Cโ€™ prompt sequences (check the prompt shell variable bestie) indicate skipped directories with an ellipsis (โ€˜...โ€™) instead of โ€˜/<skipped>โ€™. much cuter honestly โœจ
  • euid (+) The user's effective user ID.
  • euser (+) The first matching passwd entry name corresponding to the effective user ID ๐Ÿ‘‘
  • fignore (+) Lists file name suffixes to be ignored by completion. the "not invited to the party" list ๐ŸŽ€
  • filec In tcsh, completion is always used and this variable is ignored by default. like, it's just built different.

If edit is unset, then the traditional csh(1) completion is used.

If set in csh(1), filename completion is used.

  • gid (+) The user's real group ID.
  • globdot (+) If set, wild-card glob patterns will match files and directories beginning with โ€˜.โ€™ โ€” except for โ€˜.โ€™ and โ€˜..โ€™. those two stay excluded, no cap ๐Ÿ™…
  • globstar (+) If set, the โ€˜โ€™ and โ€˜*โ€™ file glob patterns will match any string of characters including โ€˜/โ€™, traversing any existing sub-directories. For example,
ls **.c

will list all the .c files in the current directory tree. deep dive behaviour ๐Ÿ•ต๏ธโ€โ™€๏ธ

If used by itself, it'll match zero or more sub-directories. For example,

ls /usr/include/**/time.h

will list any file named โ€˜time.hโ€™ in the /usr/include directory tree; whereas

ls /usr/include/**time.h

will match any file in the /usr/include directory tree ending in โ€˜time.hโ€™.

To prevent problems with recursion, the โ€˜โ€™ glob-pattern will **not descend into a symbolic link containing a directory. To override this, use โ€˜***โ€™. one extra star = one extra permission slip โญ
  • group (+) The user's group name.
  • highlight If set, the incremental search match (in i-search-back and i-search-fwd) and the region between the mark and the cursor are highlighted in reverse video. aesthetic ๐Ÿ’–
Highlighting requires more frequent terminal writes, which introduces extra overhead. If you care about terminal performance, you may want to leave this unset. your terminal will be sweating otherwise ๐Ÿ˜ญ
  • 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 โ€˜!โ€™.

The second character of its value replaces the character โ€˜^โ€™ in quick substitutions.

  • histdup (+) Controls handling of duplicate entries in the history list. pick your flavour:
    • If set to โ€˜allโ€™ โ€” only unique history events get entered in the history list.
    • If set to โ€˜prevโ€™ โ€” if 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โ€™ โ€” if the same event is found in the history list, that old event gets erased and the current one gets inserted. out with the old ๐Ÿซถ

Heads up: the โ€˜prevโ€™ and โ€˜allโ€™ options renumber history events so there are no gaps. clean numbering, tidy vibes โœจ

  • histfile (+) The default location where
history -S

and

history -L

look for a history file.

If it's unset, ~/.history is used.

histfile is genuinely so useful when you're sharing the same home directory between different machines, or when saving separate histories on different terminals. And because only ~/.tcshrc is normally sourced before ~/.history, histfile should be set in ~/.tcshrc rather than ~/.login. the ordering thing again, iykyk ๐Ÿฆ‹

  • histlit (+) If set, builtin and editor commands and the savehist mechanism use the literal (unexpanded) form of lines in the history list. Also see the toggle-literal-history editor command.
  • history The first word indicates the number of history events to save. save that lore ๐Ÿ“š

The optional second word (+) indicates the format in which history is printed; if it's not given, โ€˜%h\t%T\t%R\nโ€™ is used. The format sequences are described below under prompt; note the variable meaning of โ€˜%Rโ€™.

Set to โ€˜100โ€™ by default.

  • home Initialized to the home directory of the invoker. The filename expansion of โ€˜~โ€™ refers to this variable. home sweet home ๐Ÿ ๐Ÿ’–

okay so, next stack of shell-variable lore, bestie โ€” keep your notes app open:

  • ignoreeof โ€” if this is set to the empty string or 0, and the input device is a terminal, then the end-of-file command (usually you typing ^D on an empty line) makes the shell print this instead of dipping out:
Use "exit" to leave tcsh.

itโ€™s literally there to stop the shell from accidentally getting killed ๐Ÿ’€. historically, this setting exited after 26 successive EOFโ€™s to avoid infinite loops.

if itโ€™s set to a number n, the shell ignores n - 1 consecutive end-of-files and exits on the nth (+).

if itโ€™s unset, 1 is used โ€” i.e., the shell exits on a single ^D.

  • implicitcd (+) โ€” if set, the shell treats a directory name typed as a command as though it were a request to change to that directory.

if set to verbose, the change of directory is echoed to the standard output.

this behavior is inhibited in non-interactive shell scripts, or for command strings with more than one word. changing directory takes precedence over executing a like-named command, but itโ€™s done after alias substitutions. tilde and variable expansions work as expected โœจ.

  • inputmode (+) โ€” if set to insert or overwrite, it puts the editor into that input mode at the beginning of each line.
  • killdup (+) โ€” controls handling of duplicate entries in the kill ring.
    • if set to all, only unique strings are entered in the kill ring.
    • if set to prev, and the last killed string is the same as the current killed string, then the current string is not entered in the ring.
    • if set to erase, and the same string is found in the kill ring, the old string is erased and the current one is inserted.
  • killring (+) โ€” indicates the number of killed strings to keep in memory.

set to 30 by default.

if unset or set to less than 2, the shell will only keep the most recently killed string.

strings are put in the killring by the editor commands that delete (kill) strings of text, e.g. backward-delete-word, kill-line, etc, as well as the copy-region-as-kill command. the yank editor command will yank the most recently killed string into the command-line, while yank-pop (see โ€œEditor commands (+)โ€) can be used to yank earlier killed strings ๐ŸŽ€.

  • listflags (+) โ€” if set to x, a, or A, or any combination thereof (e.g., xA), theyโ€™re used as flags to ls-F, making it act like:
ls -xF
ls -Fa
ls -FA

or a combination, for example:

ls -FxA

if the first word contains a, it shows all files (even if they start with a .).

if the first word contains A, it shows all files but . and ...

if the first word contains x, it sorts across instead of down.

if the second word of listflags is set, itโ€™s 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 builtin command shows the type of file to which each symbolic link points ๐Ÿ”—.
  • listmax (+) โ€” the maximum number of items which the list-choices editor command will list without asking first.
  • listmaxrows (+) โ€” the maximum number of rows of items which the list-choices editor command will list without asking first.
  • loginsh (+) โ€” set by the shell if itโ€™s 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 โ€œSignal handlingโ€). see also the autologout shell variable.
  • mail โ€” a list of files and directories to check for incoming mail, optionally preceded by a numeric word. before each prompt, if 10 minutes have passed since the last check, the shell checks each file and displays:
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โ€™re in a login shell, then no mail file is reported unless it has been modified after the time the shell has started up, to prevent redundant notifications. most login programs will tell you whether or not you have mail when you log in.

if a file specified in mail is a directory, the shell will count each file within that directory as a separate message, and will report:

You have n mails.

or:

You have n mails in name.

as appropriate. this functionality is provided primarily for those systems which store mail in this manner, such as the Andrew Mail System ๐Ÿ“ฌ.

if the first word of mail is numeric, itโ€™s taken as a different mail checking interval, in seconds.

under very rare circumstances, the shell may report:

You have mail.

instead of:

You have new mail.
  • matchbeep (+) โ€” if set to never, completion never beeps.

if set to nomatch, it beeps only when there is no match.

if set to ambiguous, it beeps when there are multiple matches.

if set to notunique, it beeps when there is one exact and other longer matches.

if unset, ambiguous is used.

  • nobeep (+) โ€” if set, beeping is completely disabled. see also visiblebell ๐Ÿ”•.
  • noclobber โ€” if set, restrictions are placed on output redirection to insure that files are not accidentally destroyed and that >> redirections refer to existing files, as described in the โ€œInput/outputโ€ section.

if contains ask, an interactive confirmation is presented, rather than an error.

if contains notempty, > is allowed on empty files.

  • noding โ€” if set, disable the printing of:
DING!

in the prompt time specifiers at the change of hour.

  • noglob โ€” if set, โ€œFilename substitutionโ€ and โ€œDirectory stack substitution (+)โ€ are inhibited. this is most useful in shell scripts which do not deal with filenames, or after a list of filenames has been obtained and further expansions are not desirable.
  • nokanji (+) โ€” if set and the shell supports Kanji (see the version shell variable), itโ€™s disabled so that the meta key can be used.
  • nonomatch โ€” if set, a โ€œFilename substitutionโ€ or โ€œDirectory stack substitution (+)โ€ which does not match any existing files is left untouched rather than causing an error. itโ€™s still an error for the substitution to be malformed. for example:
echo [

still gives an error.

  • nostat (+) โ€” a list of directories (or glob-patterns which match directories; see โ€œFilename substitutionโ€) that should not be stat(2)ed during a completion operation. this is usually used to exclude directories which take too much time to stat(2), for example /afs.
  • notify โ€” if set, the shell announces job completions asynchronously. the default is to present job completions just before printing a prompt.
  • oid (+) โ€” the user's real organization ID. (Domain/OS only)
  • owd (+) โ€” the old working directory, equivalent to the - used by cd and pushd. see also the cwd and dirstack shell variables.
  • padhour โ€” if set, enable the printing of padding 0 for hours, in 24 and 12 hour formats. e.g., 07:45:42 versus 7:45:42.
  • parseoctal โ€” to retain compatibility with older versions, numeric variables starting with 0 are not interpreted as octal. setting this variable enables proper octal parsing.
  • 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 execute.

path is set by the shell at startup from the PATH environment variable or, if PATH does not exist, to a system-dependent default, such as:

(/usr/local/bin /usr/bsd /bin /usr/bin .)

the shell may 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 one adds a new command to a directory in path while the shell is active, one may need to do a rehash for the shell to find it ๐Ÿงš.

  • printexitvalue (+) โ€” if set and an interactive program exits with a non-zero status, the shell prints:
Exit status
  • prompt โ€” the string which is printed before reading each command from the terminal.

prompt may 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 โ€œFilename substitutionโ€. ~user substitution happens only if the shell has already used ~user in a pathname in the current session.
  • %c[[0]n], %.[[0]n] โ€” the trailing component of the cwd โœจ, or n trailing components if you give it a digit n. If n starts with a 0, the number of skipped components gets stuck in front of the trailing bit(s) in the format /<skipped>trailing. And if the ellipsis shell variable is set, those skipped components become an ellipsis, so the whole thing looks like ...trailing. The ~ substitution happens like in %~ above, except the ~ component gets ignored when counting trailing components. ๐ŸŽ€
  • %C โ€” literally %c but with no ~ substitution. that's it. that's the vibe check. ๐Ÿ’…
  • %h, %!, ! โ€” the current history event number ๐Ÿ•ฐ๏ธ
  • %M โ€” the full hostname, government name and all ๐Ÿ‘‘
  • %m โ€” the hostname up to the first . (so, the nickname)
  • %S (%s) โ€” start (stop) standout mode โœจ
  • %B (%b) โ€” start (stop) boldfacing mode, bold bestie behavior ๐Ÿซถ
  • %U (%u) โ€” start (stop) underline mode, very "look at me" of it
  • %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, seconds included ๐Ÿ˜ค
  • %P โ€” like %p but in 24-hour format (but see the ampm shell variable again)
  • \c โ€” c is parsed as in bindkey
  • ^c โ€” c is parsed as in bindkey
  • %% โ€” one singular %, no more no less ๐Ÿ“
  • %n โ€” the user name
  • %N โ€” the effective user name (iykyk)
  • %j โ€” the number of jobs ๐Ÿ’€
  • %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 shell's tty
  • %L โ€” clears from the end of the prompt to the 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 ๐Ÿ‘‘ lowkey the flex sequence
  • %{string%} โ€” includes string as a literal escape sequence. Only use it to change terminal attributes, and it should not move the cursor location. Also, this absolutely cannot be the last sequence in the prompt. no cap.
  • %? โ€” 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. multitasking icon ๐Ÿ’…

So %B, %S, %U, and %{string%} are available in only eight-bit-clean shells โ€” check the version shell variable bestie.

The bold, standout and underline sequences are often used to distinguish a superuser shell. For example:

> set prompt = "%m [%h] %B[%@]%b [%/] you rang? "
tut [37] [2:54pm] [/usr/accts/sys] you rang? _

And here's the little jump-scare: if %t, %@, %T, %p, or %P is used, and noding is not set, then it prints

DING!

on the change of hour (i.e, :00 minutes) instead of the actual time. yes it really dings at you ๐Ÿ˜ญ

Set by default to %# in interactive shells.


๐ŸŒธ prompt2 (+)

The string with which to prompt in while and foreach loops and after lines ending in \. Same format sequences as prompt โ€” just 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. Same format sequences may be used as in prompt; again, 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 gets replaced with the first character for normal users and the second character for the superuser. cute and functional ๐Ÿซถ


๐Ÿฆ‹ pushdtohome (+)

If set, pushd with no arguments does

pushd ~

just like cd does. no notes.


๐ŸŒˆ pushdsilent (+)

If set, pushd and popd do not print the directory stack. stealth mode activated ๐Ÿคซ


โญ recexact (+)

If set, completion completes on an exact match even if a longer match is possible. sometimes you just know.


๐Ÿ”ฅ recognize_only_executables (+)

If set, command listing displays only files in the path that are executable. It's slow. like, worth-it-slow? you decide ๐ŸŒ


๐Ÿ™ˆ rmstar (+)

If set, the user is prompted before

rm *

is executed. genuinely a glow-up for your filesystem, protect her at all costs ๐Ÿ’–


๐Ÿงš rprompt (+)

The string to print on the right-hand side of the screen (after the command input) when the prompt is being displayed on the left. It 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 appear only if the prompt, command input, and itself will fit together on the first line. so considerate of it โœจ

If edit isn't set, then rprompt will be printed after the prompt and before the command input.


๐Ÿ“ savedirs (+)

If set, the shell does

dirs -S

before exiting.

If the first word is set to a number, at most that many directory stack entries are saved. budgeting, we love to see it ๐Ÿ’…


๐Ÿ’ซ savehist

If set, the shell does

history -S

before exiting.

If the first word is set to a number, at most that many lines are saved. (The number should be less than or equal to the number of history entries; if it is set to greater than the number of history settings, only history entries will be saved.) math is math-ing ๐Ÿ“

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.

If the second word is set to merge and the third word is set to lock, the history file update will be serialized with other shell sessions that would possibly like to merge history at exactly the same time. (+) no fighting over the history file besties ๐Ÿซถ


โณ sched (+)

The format in which the sched builtin command prints scheduled events; if not given, %h\t%T\t%R\n is used. The format sequences are described above 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 the description of "Builtin and non-builtin 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 exit status from the last command or backquote expansion, or any command in a pipeline is propagated to status. (This is also the default csh(1) behavior.) This default does not match what POSIX mandates (to return the status of the last command only). To match the POSIX behavior, you need to unset anyerror. โš ๏ธ

If the anyerror variable is unset, the exit status of a pipeline is determined only from the last command in the pipeline, and the exit status of a backquote expansion is not propagated to status.

If a command terminated abnormally, then 0200 is added to the status. Builtin commands which fail return exit status 1, all other builtin commands return status 0.


Can be set to several different values to control symbolic link (symlink) resolution:

  • 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; this is a bug. ๐Ÿ’€
  • ignore โ€” the shell tries to construct a current directory relative to the current directory before the link was crossed. This means that
cd

through a symbolic link and then

cd ..

returns one to the original directory. This affects only builtin commands and filename completion.

  • expand โ€” the shell tries to fix symbolic links by actually expanding arguments which look like path names. This affects any command, not just builtins. Unfortunately, this does not work for hard-to-recognize filenames, such as those embedded in command options. Expansion may be prevented by quoting. While this setting is usually 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. balance, bestie โš–๏ธ

Some examples are in order. First, let's set up some play directories:

> cd /tmp
> mkdir from from/src to
> ln -s from/src to/dst

Here's the behavior with symlinks unset,

> cd /tmp/to/dst; echo $cwd
/tmp/to/dst
> cd ..; echo $cwd
/tmp/from

Here's the behavior with symlinks set to chase,

> cd /tmp/to/dst; echo $cwd
/tmp/from/src
> cd ..; echo $cwd
/tmp/from

Here's the behavior with symlinks set to ignore,

> cd /tmp/to/dst; echo $cwd
/tmp/to/dst
> cd ..; echo $cwd
/tmp/to

So that was the ignore vibe. Now bestie, here's what it does when symlinks is set to expand โ€” whole different energy:

> cd /tmp/to/dst; echo $cwd
/tmp/to/dst
> cd ..; echo $cwd
/tmp/to
> cd /tmp/to/dst; echo $cwd
/tmp/to/dst
> cd ".."; echo $cwd
/tmp/from
> /bin/echo ..
/tmp/to
> /bin/echo ".."
..

And like, the way to remember what expand is giving:

  1. It works just like ignore for builtins like cd. ๐Ÿ’…
  2. Quoting literally stops it. Periodt.
  3. It happens before filenames get passed to non-builtin commands.

  • tcsh (+) โ€” The version number of the shell, formatted like R.VV.PP, where R is the major release number, VV is the current version, and PP is the patchlevel. ๐Ÿ”ฅ
  • term โ€” The terminal type. Usually you set this in ~/.login, as described up in "Startup and shutdown" iykyk.
  • time โ€” If you set it to a number, the time builtin runs automatically after every command that takes more than that many CPU seconds. โฑ๏ธ

And if there's a second word? That's your format string for the time builtin's output. Fancy.

(u) These sequences are allowed in the time format string:

  • %U โ€” The time the process spent in user mode in cpu seconds.
  • %S โ€” The time the process spent in kernel mode in cpu seconds.
  • %E โ€” The elapsed (wall clock) time in seconds.
  • %P โ€” The CPU percentage computed as (%U + %S) / %E.
  • %W โ€” Number of times the process was swapped.
  • %X โ€” The average amount in (shared) text space used in Kbytes.
  • %D โ€” The average amount in (unshared) data/stack space 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 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.

Heads up: only the first four sequences are supported on systems without BSD resource limit functions ๐Ÿ˜ญ. The default time format is %Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww for systems that support resource usage reporting, and %Uu %Ss %E %P for systems that don't.

Now, under Sequent's DYNIX/ptx, %X, %D, %K, %r, and %s are not available โ€” but these extra sequences are, bestie:

  • %Y โ€” The number of system calls performed.
  • %Z โ€” The number of pages which are zero-filled on demand.
  • %i โ€” The number of times a process's resident set size was increased by the kernel.
  • %d โ€” The number of times a process's resident set size was decreased by the kernel.
  • %l โ€” The number of read system calls performed.
  • %m โ€” The number of write system calls performed.
  • %p โ€” The number of reads from raw disk devices.
  • %q โ€” The number of writes to raw disk devices.

...and there the default time format is %Uu %Ss %E %P %I+%Oio %Fpf+%Ww.

Ngl, the CPU percentage can totally be higher than 100% on multi-processors. Not a bug, just math being math. ๐Ÿ”ฅ
  • tperiod (+) โ€” The period, in minutes, between executions of the periodic special alias.
  • tty (+) โ€” The name of the tty, or empty if you're not attached to one.
  • uid (+) โ€” The user's real user ID.
  • user โ€” The user's login name.
  • verbose โ€” If set, it causes the words of each command to be printed, after history substitution (if any). It's 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) and a comma-separated list of options which were set at compile time. Options which are set by default in the distribution are noted. ๐ŸŽ€

Supported version options include:

  • 8b โ€” The shell is eight bit clean; default.
  • 7b โ€” The shell is not eight bit clean.
  • wide โ€” The shell is multi-byte encoding clean (like UTF-8). ๐ŸŒˆ
  • nls โ€” The system's NLS is used; default for systems with NLS.
  • lf โ€” Login shells execute /etc/csh.login before instead of after /etc/csh.cshrc and ~/.login before instead of after ~/.tcshrc and ~/.history.
  • dl โ€” . is put last in path for security; default.
  • nd โ€” . is omitted from path for security.
  • vi โ€” vi(1)-style editing is the default rather than emacs(1)-style.
  • dtr โ€” Login shells drop DTR when exiting.
  • bye โ€” bye is a synonym for logout and log is an alternate name for watchlog.
  • al โ€” autologout is enabled; default.
  • kan โ€” Kanji is used if appropriate according to locale settings, unless the nokanji shell variable is set.
  • sm โ€” The system's malloc(3) is used.
  • hb โ€” The
#!interpreter arg ...

convention is emulated when executing shell scripts.

  • ng โ€” The newgrp builtin is available.
  • rh โ€” The shell attempts to set the REMOTEHOST environment variable.
  • afs โ€” The shell verifies your password with the kerberos server if local authentication fails. The afsuser shell variable or the AFSUSER environment variable override your local username if set.

An administrator may enter additional strings to indicate differences in the local version. ๐Ÿ‘‘

  • vimode (+) โ€” If unset, various key bindings change behavior to be more emacs(1)-style: word boundaries are determined by wordchars versus other characters.

If set, various key bindings change behavior to be more vi(1)-style: word boundaries are determined by wordchars versus whitespace versus other characters; cursor behavior depends upon current vi mode (command, delete, insert, replace).

This variable is unset by bindkey -e and set by bindkey -v. vimode may be explicitly set or unset by the user after those bindkey operations if required.

  • visiblebell (+) โ€” If set, a screen flash is used rather than the audible bell. See also nobeep. โœจ
  • watch (+) โ€” A list of user/terminal pairs to watch for logins and logouts. If either the user is any, all terminals are watched for the given user and vice versa. Setting watch to
(any any)

watches all users and terminals. For example,

set watch = (george ttyd1 any console $user any)

reports activity of the user george on ttyd1, any user on the console, and oneself (or a trespasser) on any terminal. ๐Ÿ‘€

Logins and logouts are checked every 10 minutes by default, but the first word of watch can be set to a number to check every so many minutes. For example,

set watch = (1 any any)

reports any login/logout once every minute. For the impatient, the log builtin command triggers a watch report at any time. All current logins are reported (as with the log builtin) 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:
    • %n โ€” The name of the user who logged in/out.
    • %a โ€” The observed action, i.e., logged on, logged off, or replaced olduser on.
    • %l โ€” The terminal (tty) on which the user logged in/out.
    • %M โ€” The full hostname of the remote host, or local if the login/logout was from the local host.
    • %m โ€” The hostname of the remote host up to the first .. The full name is printed if it is an IP address or an X Window System display.

%M and %m are available on only systems that store the remote hostname in /etc/utmp.

If unset,

%n has %a %l from %m.

is used, or

%n has %a %l.

on systems which don't store the remote hostname.

  • wordchars (+) โ€” A list of non-alphanumeric characters to be considered part of a word by the forward-word, backward-word, etc., editor commands.

If unset, the default value is determined based on the state of vimode: if vimode is unset, *?_-.[]~= is used as the default; if vimode is set, _ is used as the default.


๐ŸŒ ENVIRONMENT ๐ŸŒ

  • AFSUSER (+) โ€” Equivalent to the afsuser shell variable. ๐Ÿซถ

CLICOLOR_FORCE

So ls-F normally turns off its color sequences when the output isn't going to a terminal (sad, I know ๐Ÿ’”). Set this variable and you override that โ€” it also flips the ls-F invocation of ls(1) from --color=auto over to --color=always.

โš ๏ธ plot twist: color has to be set for this env var to actually do anything. CLICOLOR_FORCE by itself does not enable color ls-F. no cap.

COMMAND_LINE

tcsh sets this one for you โ€” it's the current command line, handed over when invoking programs for the complete list mode `...`. See complete in "Builtin commands".

COLUMNS

The number of columns in your terminal. See "Terminal management (+)".

DISPLAY

Used by the X Window System (peep X(1) ๐Ÿ’ป). If it's set, the shell does not set autologout.

EDITOR

The pathname to a default editor. It's what the run-fg-editor editor command reaches for when the editors shell variable is unset. Also see the VISUAL environment variable, bestie ๐Ÿซถ

GROUP (+)

Equivalent to the group shell variable.

HOME

Equivalent to the home shell variable. (yes, the classic ๐Ÿ )

HOST (+)

Initialized to the name of the machine the shell is running on, as determined by the gethostname(2) system call.

HOSTTYPE (+)

Initialized to the type of machine the shell is running on, determined at compile time.

๐Ÿ’€ heads up: this variable is obsolete and will be removed in a future version. Don't get attached.

HPATH (+)

A ':'-separated list of directories where the run-help editor command goes looking for command documentation.

LANG

Gives the preferred character environment. See "Native Language System support (+)".

LC_CTYPE

If set, only ctype character handling changes. See "Native Language System support (+)".

LINES

The number of lines in your terminal. See "Terminal management (+)".

LSCOLORS

One of the two environment variables that may be used to define the per-file colors used by ls-F (the other one's LS_COLORS, obviously ๐Ÿ’…). This particular one is used by some BSD versions of ls(1).

The priority situation, because it's giving drama:

  • On tcsh startup, LS_COLORS takes priority over LSCOLORS.
  • If both LSCOLORS or LS_COLORS are setenv, the most recent setenv wins.
  • If LSCOLORS is unsetenv while LS_COLORS is still setenv, then LS_COLORS gets parsed again (with any warnings suppressed) to reapply its settings.

This variable is a 22 character string โ€” a concatenation of 11 pairs in the format fb, where f is the foreground color and b is the background color. Fewer than 11 pairs? Default colors fill in the rest. More than 11? The extra values are literally ignored, sorry ๐Ÿ˜ญ

The order of the color attribute pairs, mapped to the equivalent LS_COLORS variable, file type, and default color:

  • 1 ยท di โ€” Directory. [Bold blue]
  • 2 ยท ln โ€” Symbolic link. [Bold cyan]
  • 3 ยท so โ€” Socket. [Bold magenta]
  • 4 ยท pi โ€” Named pipe (FIFO). [Yellow (or brown)]
  • 5 ยท ex โ€” Executable file. [Bold green]
  • 6 ยท bd โ€” Block device. [Bold yellow]
  • 7 ยท cd โ€” Character device. [Bold yellow]
  • 8 ยท su โ€” Setuid file. [White on red]
  • 9 ยท sg โ€” Setgid file. [Black on yellow]
  • 10 ยท tw โ€” Sticky and other writable directory. [Black on green]
  • 11 ยท ow โ€” Other writable but not sticky directory. [Blue on green]

The color code designators, bestie, memorize these ๐ŸŒˆ:

  • a โ€” Black.
  • b โ€” Red.
  • c โ€” Green.
  • d โ€” Yellow (or brown).
  • e โ€” Blue.
  • f โ€” Magenta.
  • g โ€” Cyan.
  • h โ€” Light grey.
  • A โ€” Bold black, usually shows up as dark grey.
  • B โ€” Bold red.
  • C โ€” Bold green.
  • D โ€” Bold yellow.
  • E โ€” Bold blue.
  • F โ€” Bold magenta.
  • G โ€” Bold cyan.
  • H โ€” Bold light grey; looks like bright white.
  • x โ€” Default foreground or background.

Note that the above are standard ANSI colors โ€” the actual display may differ depending on the color capabilities of the terminal you're using. Your mileage may literally vary ๐ŸŽจ

Also: the default colors are as per the color variables in LS_COLORS, and they are not the same default colors as those used by some BSD versions of ls(1).

LS_COLORS

The other one of the two environment variables that may be used to define the per-file colors used by ls-F (along with LSCOLORS). This one is used by the GNU coreutils version of ls(1) and may be setup by dircolors(1).

Same priority rules as before, because the shell is consistent like that โœจ:

  • On tcsh startup, LS_COLORS takes priority over LSCOLORS.
  • If both LSCOLORS or LS_COLORS are setenv, the most recent setenv is used.
  • If LS_COLORS is unsetenv while LSCOLORS is still setenv, then LSCOLORS is parsed again (with any warnings suppressed) to reapply its settings.

The format is giving termcap(5) energy โ€” a ':'-separated list of expressions of the form "xx=value" or "*ext=value".

The "xx=value" form

Here "xx" is a two-character variable name. The supported variables, their associated default ISO 6429 color code or escape sequences, and file type:

  • no โ€” default 0 โ€” Normal (non-filename) text.
  • fi โ€” default 0 โ€” Regular file.
  • di โ€” default 01;34 โ€” Directory. [Bold blue]
  • ln โ€” default 01;36 โ€” Symbolic link. [Bold cyan]
  • pi โ€” default 33 โ€” Named pipe (FIFO). [Yellow (or brown)]
  • so โ€” default 01;35 โ€” Socket. [Bold magenta]
  • do โ€” default 01;35 โ€” Door. [Bold magenta]
  • bd โ€” default 01;33 โ€” Block device. [Bold yellow]
  • cd โ€” default 01;33 โ€” Character device. [Bold yellow]
  • ex โ€” default 01;32 โ€” Executable file. [Bold green]
  • mi โ€” default (none) โ€” Missing file (orphaned symbolic link target). Defaults to fi.
  • or โ€” default (none) โ€” Orphaned (broken) symbolic link. Defaults to ln.
  • lc โ€” default ^[[ โ€” Left code.
  • rc โ€” default m โ€” Right code.
  • ec โ€” default (none) โ€” End code. Replaces lc+no+rc.
  • su โ€” default 37;41 โ€” Setuid file. [White on red]
  • sg โ€” default 30;43 โ€” Setgid file. [Black on yellow]
  • tw โ€” default 30;42 โ€” Sticky and other writable directory. [Black on green]
  • ow โ€” default 34;42 โ€” Other writable but not sticky directory. [Blue on green]
  • st โ€” default 37;44 โ€” Sticky but not other writable directory. [White on blue]
  • mh โ€” default (none) โ€” File with multiple hard links.

You only need to include the variables you actually want to change from the default. Less is more, icon behavior ๐Ÿ‘‘

The "*ext=value" form

This one colorizes file names based on extension. Example: using ISO 6429 codes, to color all C-language source files blue you'd specify "*.c=34". That colors every file ending in .c in blue foreground (34) color. slay ๐Ÿ’™

Control characters & the codes

Control characters can be written either in C-style-escaped notation, or in stty-like ^-notation. The C-style notation adds ^[ for Escape, _ for a normal space character, and ? for Delete. On top of that, the ^[ escape character can be used to override the default interpretation of ^[, ^, :, and =.

Each filename gets output to the terminal as:

lc color-code rc filename ec

If the ec code is undefined, this sequence is used instead:

lc no rc

That's generally more convenient to use, but less general. Trade-offs, bestie.

The left code (lc), right code (rc), and end codes (ec) exist so you don't have to type common parts over and over again, and to support weird terminals. You will generally not need to change them at all โ€” unless your terminal doesn't use ISO 6429 color codes but some different system.

If your terminal does use ISO 6429 color codes, you can compose the type codes (i.e., all except the lc, rc, and ec codes) from numerical ISO 6429 color codes separated by ;. For example, 01;32 is bright green foreground with default background. cute ๐Ÿ“

The most common ISO 6429 color codes:

  • 0 โ€” To restore default color.
  • 1 โ€” Bold / brighter colors.
  • 4 โ€” Underlined text.
  • 5 โ€” Flashing text.
  • 30 โ€” Black foreground.
  • 31 โ€” Red foreground.
  • 32 โ€” Green foreground.
  • 33 โ€” Yellow (or brown) foreground.
  • 34 โ€” Blue foreground.
  • 35 โ€” Magenta foreground.
  • 36 โ€” Cyan foreground.
  • 37 โ€” White (or gray) foreground.
  • 40 โ€” Black background.
  • 41 โ€” Red background.
  • 42 โ€” Green background.
  • 43 โ€” Yellow (or brown) background.
  • 44 โ€” Blue background.
  • 45 โ€” Magenta background.
  • 46 โ€” Cyan background.
  • 47 โ€” White (or gray) background.
Real talk: not all ISO 6429 color codes will work on all systems or display devices. No fixing that one, babes.

A few terminal programs do not recognize the default end code properly. If all your text gets colorized after you do a directory listing, try changing the no and fi codes from 0 to the numerical codes for your standard foreground and background colors. That's the fix ๐Ÿ™ˆ

And finally โ€” for symbolic links, the ln keyword can be set to target, which makes the file color the same as the color of the link target. obsessed ๐Ÿฆ‹

okay bestie, last lilโ€™ env-var batch and honestly? iconic behavior only ๐Ÿ’…

  • 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. See โ€œNative Language System support (+)โ€.
  • OSTYPE (+) โ€” The operating system, as determined at compile time. ๐Ÿ“
  • PATH โ€” A :-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.
  • REMOTEHOST (+) โ€” The host from which the user has logged in remotely, if this is the case and the shell is able to determine it. Set only if the shell was so compiled; see the version shell variable.
  • SHLVL (+) โ€” Equivalent to the shlvl shell variable.
  • SYSTYPE (+) โ€” The current system type. (Domain/OS only)
  • TERM โ€” Equivalent to the term shell variable.
  • TERMCAP โ€” The terminal capability string. See โ€œTerminal management (+)โ€.
  • USER โ€” Equivalent to the user shell variable.
  • VENDOR (+) โ€” The vendor, as determined at compile time.
  • VISUAL โ€” The pathname to a default full-screen editor. Used by the run-fg-editor editor command if the the editors shell variable is unset. See also the EDITOR environment variable. ๐ŸŽ€

๐Ÿ—‚๏ธ FILES ๐Ÿ—‚๏ธ

  • /etc/csh.cshrc โ€” Read first by every shell.
    • ConvexOS, Stellix and Intel use /etc/cshrc.
    • NeXTs use /etc/cshrc.std.
    • A/UX, AMIX, Cray and IRIX have no equivalent in csh(1), but read this file in tcsh anyway.
    • Solaris 2.x does not have it either, but tcsh reads /etc/.cshrc. (+)
  • /etc/csh.login โ€” Read by login shells after /etc/csh.cshrc.
    • ConvexOS, Stellix and Intel use /etc/login.
    • NeXTs use /etc/login.std.
    • Solaris 2.x uses /etc/.login.
    • A/UX, AMIX, Cray and IRIX use /etc/cshrc.
  • ~/.tcshrc (+) โ€” Read by every shell after /etc/csh.cshrc or its equivalent.
  • ~/.cshrc โ€” Read by every shell, if ~/.tcshrc doesn't exist, after /etc/csh.cshrc or its equivalent.

This manual uses ~/.tcshrc to mean โ€œ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrcโ€.

  • ~/.history โ€” Read by login shells after ~/.tcshrc if savehist is set, but see also histfile.
  • ~/.login โ€” Read by login shells after ~/.tcshrc or ~/.history.

The shell may be compiled to read ~/.login before instead of after ~/.tcshrc and ~/.history; see the version shell variable.

  • ~/.cshdirs (+) โ€” Read by login shells after ~/.login if savedirs is set, but see also dirsfile.
  • /etc/csh.logout โ€” Read by login shells at logout.
    • ConvexOS, Stellix and Intel use /etc/logout. NeXTs use /etc/logout.std.
    • A/UX, AMIX, Cray and IRIX have no equivalent in csh(1), but read this file in tcsh anyway.
    • Solaris 2.x does not have it either, but tcsh reads /etc/.logout. (+)
  • ~/.logout โ€” Read by login shells at logout after /etc/csh.logout or its equivalent.
  • /bin/sh โ€” Used to interpret shell scripts not starting with a #.
  • /tmp/sh* โ€” Temporary file for <<.
  • /etc/passwd โ€” Source of home directories for ~name substitutions.

The order in which startup files are read may differ if the shell was so compiled; see โ€œStartup and shutdownโ€ and the version shell variable.


โœจ NEW FEATURES (+) โœจ

This manual describes tcsh as a single entity, but experienced csh(1) users will want to pay special attention to tcsh's new features. ๐Ÿซถ

  • A command-line editor, which supports emacs(1)-style or vi(1)-style key bindings. See โ€œThe command-line editor (+)โ€ and โ€œEditor commands (+)โ€. โŒจ๏ธ
  • Programmable, interactive word completion and listing. See โ€œCompletion and listing (+)โ€ and the complete and uncomplete builtin commands.
  • โ€œSpelling correction (+)โ€ of filenames, commands and variables. ๐Ÿ”ฅ
  • โ€œEditor commands (+)โ€ which perform other useful functions in the middle of typed commands, including documentation lookup (run-help), quick editor restarting (run-fg-editor), and command resolution (which-command).
  • An enhanced history mechanism. Events in the history list are time-stamped. See also the history command and its associated shell variables, the previously undocumented # event specifier and new modifiers under โ€œHistory substitutionโ€, the down-history, expand-history, history-search-backward, history-search-forward, i-search-back, i-search-fwd, toggle-literal-history, vi-search-back, vi-search-fwd, and up-history editor commands and the histlit shell variable. ๐Ÿ˜ญ
  • Enhanced directory parsing and directory stack handling. See the cd, pushd, popd, and dirs commands and their associated shell variables, the description of โ€œDirectory stack substitution (+)โ€, the dirstack, owd, and symlinks shell variables and the normalize-command and normalize-path editor commands.
  • Negation in glob-patterns. See โ€œFilename substitutionโ€.
  • New โ€œFile inquiry operatorsโ€ and a filetest builtin which uses them. ๐Ÿ”
  • A variety of โ€œAutomatic, periodic and timed events (+)โ€ including scheduled events, special aliases, automatic logout and terminal locking, command timing and watching for logins and logouts. ๐Ÿ•ฐ๏ธ
  • Support for the Native Language System (see โ€œNative Language System support (+)โ€), OS variant features (see โ€œOS variant support (+)โ€ and the echo_style shell variable) and system-dependent file locations (see โ€œFILESโ€).
  • Extensive terminal-management capabilities. See โ€œTerminal management (+)โ€.
  • New builtin commands including builtins, hup, ls-F, newgrp, printenv, which, and where. ๐Ÿ‘‘
  • New variables that make useful information easily available to the shell. See the gid, loginsh, oid, shlvl, tcsh, tty, uid, and version shell variables and the HOST, REMOTEHOST, VENDOR, OSTYPE, and MACHTYPE environment variables.
  • A new syntax for including useful information in the prompt string (see prompt), and special prompts for loops and spelling correction (see prompt2 and prompt3). ๐Ÿ’–
  • Read-only variables. See โ€œVariable substitutionโ€.

๐Ÿš THE T IN TCSH ๐Ÿš

History lesson, but make it gossip. In 1964, DEC produced the PDP-6. The PDP-10 was a later re-implementation. It was re-christened the DECsystem-10 in 1970 or so when DEC brought out the second model, the KI10. ๐Ÿฆ‹

TENEX was created at Bolt, Beranek & Newman (a Cambridge, Massachusetts think tank) in 1972 as an experiment in demand-paged virtual memory operating systems. They built a new pager for the DEC PDP-10 and created the OS to go with it. It was extremely successful in academia.

In 1975, DEC brought out a new model of the PDP-10, the KL10; they intended to have only a version of TENEX, which they had licensed from BBN, for the new box. They called their version TOPS-20 (their capitalization is trademarked). A lot of TOPS-10 users (The OPerating System for PDP-10) objected; thus DEC found themselves supporting two incompatible systems on the same hardware--but then there were 6 on the PDP-11! ๐Ÿ’€

TENEX, and TOPS-20 to version 3, had command completion via a user-code-level subroutine library called ULTCMD. With version 3, DEC moved all that capability and more into the monitor (kernel for you Unix types), accessed by the COMND% JSYS (Jump to SYStem instruction, the supervisor call mechanism [are my IBM roots also showing?]). ๐Ÿงš

The creator of tcsh was impressed by this feature and several others of TENEX and TOPS-20, and created a version of csh which mimicked them. ๐ŸŒˆ


๐Ÿšง LIMITATIONS ๐Ÿšง

  • The system limits argument lists to ARG_MAX characters.
  • The number of arguments to a command which involves filename expansion is limited to 1/6th the number of characters allowed in an argument list.
  • Command substitutions may 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. ๐Ÿ˜ตโ€๐Ÿ’ซ

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

Go touch grass in these other manuals, bestie: csh(1), dircolors(1), emacs(1), ls(1), newgrp(1), setpath(1), sh(1), stty(1), su(1), tset(1), vi(1), x(1), access(2), execve(2), fork(2), killpg(2), pipe(2), setrlimit(2), sigvec(2), stat(2), umask(2), vfork(2), wait(2), malloc(3), setlocale(3), tty(4), a.out(5), termcap(5), environ(7), termio(7), Introduction to the C Shell. ๐Ÿ“š


๐Ÿท๏ธ VERSION ๐Ÿท๏ธ

This manual documents tcsh 6.24.16 (Astron) 2025-07-09. ๐ŸŒธ

๐Ÿ‘‘ AUTHORS ๐Ÿ’–

okay so this shell was literally not built by one person, it's a whole group project that actually slayed, and every single one of these legends gets their flowers ๐ŸŒธ

  • William Joy. โ€” Original author of csh(1). like, the founding mother of the whole vibe, no cap
  • J.E. Kulp, IIASA, Laxenburg, Austria. โ€” Job control and directory stack features. the reason you can yeet a job into the background and pop it back, iconic
  • Ken Greer, HP Labs, 1981. โ€” File name completion. the OG tab-tab-tab era, we stan ๐Ÿซถ
  • Mike Ellis, Fairchild, 1983. โ€” Command name recognition/completion.
  • Paul Placeway, Ohio State CIS Dept., 1983-1993. โ€” Command line editor, prompt routines, new glob syntax and numerous fixes and speedups. that's a decade of service bestie, periodt
  • Karl Kleinpaste, CCI, 1983-4. โ€” Special aliases, directory stack extraction stuff, login/logout watch, scheduled events, and the idea of the new prompt format. lowkey the prompt glow-up is all him
  • Rayan Zachariassen, University of Toronto, 1984. โ€” ls-F and which builtins and numerous bug fixes, modifications and speedups.
  • Chris Kingsley, Caltech. โ€” Fast storage allocator routines. making memory go zoom, we love to see it
  • Chris Grevstad, TRW, 1987. โ€” Incorporated 4.3BSD csh(1) into tcsh. the merge that started it all fr fr
  • Christos S. Zoulas, Cornell U. EE Dept., 1987-94. โ€” Ports to HPUX, SVR2 and SVR3, a SysV version of getwd.c, SHORT_STRINGS support and a new version of sh.glob.c.
  • James J Dempsey, BBN, and Paul Placeway, OSU, 1988. โ€” A/UX port.
  • Daniel Long, NNSC, 1988. โ€” wordchars.
  • Patrick Wolfe, Kuck and Associates, Inc., 1988. โ€” vi mode cleanup.
  • David C Lawrence, Rensselaer Polytechnic Institute, 1989. โ€” autolist and ambiguous completion listing.
  • Alec Wolman, DEC, 1989. โ€” Newlines in the prompt.
  • Matt Landau, BBN, 1989. โ€” ~/.tcshrc. yes THAT file, the one in your dotfiles ๐Ÿ’…
  • Ray Moody, Purdue Physics, 1989. โ€” Magic space bar history expansion. magic space bar is genuinely such main character energy โœจ
  • Mordechai ????, Intel, 1989. โ€” printprompt() fixes and additions. (bestie's last name is literally a mystery and honestly? mysterious icon behavior)
  • Kazuhiro Honda, Dept. of Computer Science, Keio University, 1989. โ€” Automatic spelling correction and prompt3.
  • Per Hedeland, Ellemtel, Sweden, 1990-. โ€” Various bugfixes, improvements and manual updates.
  • Hans J. Albertsson, Sun Sweden. โ€” ampm, settc, and telltc.
  • Michael Bloom. โ€” Interrupt handling fixes.
  • Michael Fine, Digital Equipment Corp. โ€” Extended key support.
  • Eric Schnoebelen, Convex, 1990. โ€” Convex support, lots of csh(1) bug fixes, save and restore of directory stack.
  • Ron Flax, Apple, 1990. โ€” A/UX 2.0 (re)port.
  • Dan Oscarsson, LTH Sweden, 1990. โ€” NLS support and simulated NLS support for non NLS sites, fixes.
  • Johan Widen, SICS Sweden, 1990. โ€” shlvl, Mach support, correct-line, 8-bit printing.
  • Matt Day, Sanyo Icon, 1990. โ€” POSIX termio support, SysV limit fixes.
  • Jaap Vermeulen, Sequent, 1990-91. โ€” Vi mode fixes, expand-line, window change fixes, Symmetry port.
  • Martin Boyer, Institut de recherche d'Hydro-Quebec, 1991. โ€” autolist beeping options, modified the history search to search for the whole string from the beginning of the line to the cursor.
  • Scott Krotz, Motorola, 1991. โ€” Minix port.
  • David Dawes, Sydney U. Australia, Physics Dept., 1991. โ€” SVR4 job control fixes.
  • Kimmo Suominen, 1991-. โ€” Various portability and other fixes. Added $'' (dollar-single-quotes).
  • Jose Sousa, Interactive Systems Corp., 1991. โ€” Extended vi fixes and vi delete command.
  • Marc Horowitz, MIT, 1991. โ€” ANSIfication fixes, new exec hashing code, imake fixes, where.
  • Luke Mewburn, 1991-. โ€” Enhanced directory printing in prompt. Added ellipsis and rprompt. vimode improvements. Manual page improvements.
  • Bruce Sterling Woodcock, <sterling@netcom.com>, 1991-1995. โ€” ETA and Pyramid port, Makefile and lint fixes, ignoreeof=n addition, and various other portability changes and bug fixes.
  • Jeff Fink, 1992. โ€” complete-word-fwd and complete-word-back.
  • Harry C. Pulley, 1992. โ€” Coherent port.
  • Andy Phillips, Mullard Space Science Lab U.K., 1992. โ€” VMS-POSIX port.
  • Beto Appleton, IBM Corp., 1992. โ€” Walking process group fixes, csh(1) bug fixes, POSIX file tests, POSIX SIGHUP.
  • Scott Bolte, Cray Computer Corp., 1992. โ€” CSOS port.
  • Kaveh R. Ghazi, Rutgers University, 1992. โ€” Tek, m88k, Titan and Masscomp ports and fixes. Added autoconf support.
  • Mark Linderman, Cornell University, 1992. โ€” OS/2 port.
  • Mika Liljeberg, <liljeber@kruuna.Helsinki.FI>, 1992. โ€” Linux port.
  • Tim P. Starrin, NASA Langley Research Center Operations, 1993. โ€” Read-only variables.
  • Dave Schweisguth, Yale University, 1993-4. โ€” New man page and tcsh.man2html. (this very page's ancestor, ty bestie ๐Ÿ˜ญ)
  • Larry Schwimmer, Stanford University, 1993. โ€” AFS and HESIOD patches.
  • Edward Hutchins, Silicon Graphics Inc., 1996. โ€” Added implicit cd.
  • Martin Kraemer, 1997. โ€” Ported to Siemens Nixdorf EBCDIC machine.
  • Amol Deshpande, Microsoft, 1997. โ€” Ported to WIN32 (Windows/95 and Windows/NT); wrote all the missing library and message catalog code to interface to Windows.
  • Taga Nayuta, 1998. โ€” Color ls additions. ๐ŸŒˆ

๐Ÿซถ THANKS TO ๐ŸŒธ

  • Bryan Dunlap, Clayton Elwell, Karl Kleinpaste, Bob Manson, Steve Romig, Diana Smetters, Bob Sutterfield, Mark Verber, Elizabeth Zwicky and all the other people at Ohio State for suggestions and encouragement ๐Ÿ’œ
  • All the people on the net, for putting up with, reporting bugs in, and suggesting new additions to each and every version โ€” genuinely the real MVPs, fr fr
  • Richard M. Alderson III, for writing the "T in tcsh" section ๐Ÿ‘‘

๐Ÿ’€ BUGS ๐Ÿ’€

okay bestie, buckle up, this is the "we're honest about it" section ๐Ÿ™ˆ none of this is me being mean, it's literally in the source:

  • When a suspended command is restarted, the shell prints the directory it started in if this is different from the current directory. This can be misleading (i.e., wrong) as the job may have changed directories internally. ngl that's a little gaslight-y of the shell
  • Shell builtin 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 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, i.e.,

( a ; b ; c )
  • Control over tty output after processes are started is primitive; perhaps this will inspire someone to work on a good virtual terminal interface. In a virtual terminal interface much more interesting things could be done with output control. (calling all future icons โœจ)
  • Alias substitution is most often used to clumsily simulate shell procedures; shell procedures should be provided rather than aliases.
  • Control structures should be parsed rather than 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 ; metasyntax.
  • foreach doesn't ignore here documents when looking for its end.
  • It should be possible to use the : modifiers on the output of command substitutions.
  • The screen update for lines longer than the screen width is very poor if the terminal cannot move the cursor up (i.e., terminal type dumb). yeah dumb is doing exactly what it says on the tin ๐Ÿ’€
  • HPATH and NOREBIND don't need to be environment variables.
  • Glob-patterns which do not use ?, *, or [], or which use {} or ~ are not negated correctly.
  • The single-command form of if does output redirection even if the expression is false and the command is not executed.
  • ls-F includes file identification characters when sorting filenames and does not handle control characters in filenames well. It cannot be interrupted.
  • Command substitution supports multiple commands and conditions, but not cycles or backward gotos.
found a bug? report it at https://bugs.astron.com/ โ€” preferably with fixes ๐Ÿ’… and if you wanna help maintain and test tcsh, add yourself to the mailing list at https://mailman.astron.com/mailman/listinfo/tcsh ๐Ÿซถ

and that's the whole page bestie, you made it all the way through ๐ŸŽ€ this was Astron 6.24.16, dated July 9, 2025, filed under TCSH(1) โ€” go forth and shell responsibly, ilysm โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from