CSH(1)

๐Ÿ“ฆ
this version ยท 2 versions
, in debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

okay so bestie, you just opened the CSH(1) page from the General Commands Manual, and I am so ready to spill the tea on csh ๐Ÿ’…โœจ This shell is a whole main character, no cap.


โœจ NAME โœจ

csh โ€” a shell (command interpreter) with C-like syntax ๐Ÿš๐Ÿ’–

โœจ SYNOPSIS โœจ

csh [-bcefimnstVvXx] [argument ...]
csh [-l]

โœจ DESCRIPTION โœจ

csh is a command language interpreter incorporating a history mechanism (see โ€œHistory substitutionsโ€), job control facilities (see โ€œJobsโ€), interactive file name and user name completion (see โ€œFile name completionโ€), and a C-like syntax. It is used both as an interactive login shell and a shell script command processor. slay.

๐ŸŒธ Argument list processing ๐ŸŒธ

If the first argument (argument 0) to the shell is a dash (-), then this is a login shell. A login shell also can be specified by invoking the shell with the -l flag as the only argument.

The rest of the flag arguments are interpreted as follows:

  • -b โ€” This flag forces a โ€œbreakโ€ from option processing, causing any further shell arguments to be treated as non-option arguments. The remaining arguments will not be interpreted as shell options. This may be used to pass options to a shell script without confusion or possible subterfuge. The shell will not run a set-user-ID script without this option. ๐Ÿ›‘
  • -c โ€” Commands are read from the (single) following argument which must be present. Any remaining arguments are placed in argv. ๐Ÿ“ฅ
  • -e โ€” The shell exits if any invoked command terminates abnormally or yields a non-zero exit status. ๐Ÿ’€
  • -f โ€” The shell will start faster, because it will not execute user or system startup files, load saved history or perform command hashing. Note: if the environment variable HOME is not set, fast startup is the default. โšก
  • -i โ€” The shell is interactive and prompts for its top-level input, even if it appears not to 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 โ€” Read .cshrc, regardless of its owner and group. This option is dangerous and should only be used by su(1). ๐Ÿšจ
  • -n โ€” Commands are parsed, but not executed. This aids in syntactic checking of shell scripts. When used interactively, the shell can be terminated by pressing control-D (end-of-file character), since exit will not work. ๐Ÿง
  • -s โ€” Command input is taken from the standard input. ๐Ÿ“ฅ
  • -t โ€” A single line of input is read and executed. A backslash (\) may be used to escape the newline at the end of this line and continue onto another line. โ†ฉ๏ธ
  • -V โ€” Causes the verbose variable to be set even before .cshrc is executed. ๐Ÿ—ฃ๏ธ
  • -v โ€” Causes the verbose variable to be set, with the effect that command input is echoed after history substitution. ๐Ÿ”
  • -X โ€” Causes the echo variable to be set even before .cshrc is executed. ๐Ÿ“ข
  • -x โ€” Causes the echo variable to be set, so that commands are echoed immediately before execution. ๐Ÿ‘€

After processing of flag arguments, 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 to be executed. The shell opens this file, and saves its name for possible resubstitution by $0. Since many systems use either the standard version 6 or version 7 shells whose shell scripts are not compatible with this shell, the shell will execute such a โ€œstandardโ€ shell if the first character of a script is not a hash mark (#); i.e., if the script does not start with a comment. Remaining arguments initialize the variable argv. ๐Ÿ“œ

An instance of csh begins by executing commands from the file /etc/csh.cshrc and, if this is a login shell, /etc/csh.login. It then executes commands from .cshrc in the home directory of the invoker, and, if this is a login shell, the file .login in the same location. It is typical for users on CRTs to put the command stty crt in their .login file, and to also invoke tset(1) there. ๐Ÿ–ฅ๏ธ

In the normal case, the shell will begin reading commands from the terminal, prompting with % . Processing of arguments and the use of the shell to process files containing command scripts will be described later. ๐Ÿ’ฌ

The shell repeatedly performs the following actions: a line of command input is read and broken into โ€œwordsโ€. This sequence of words is placed on the command history list and parsed. Finally each command in the current line is executed. ๐Ÿ”„

When a login shell terminates, it executes commands from the files .logout in the user's home directory and /etc/csh.logout. ๐Ÿ‘‹

๐Ÿฆ‹ Lexical structure ๐Ÿฆ‹

The shell splits input lines into words at blanks and tabs with the following exceptions. The characters &, |, ;, <, >, (, and ) form separate words. If doubled in &&, ||, <<, or >>, these pairs form single words. These parser metacharacters may be made part of other words, or have their special meaning prevented, by preceding them with a backslash (\). A newline preceded by a \ is equivalent to a blank. โœ‚๏ธ

Strings enclosed in matched pairs of quotations, ', `, or ", form parts of a word; metacharacters in these strings, including blanks and tabs, do not form separate words. These quotations have semantics to be described later. Within pairs of ' or " characters, a newline preceded by a \ gives a true newline character. ๐Ÿ’ฌ

When the shell's input is not a terminal, the character # introduces a comment that continues to the end of the input line. This special meaning is prevented when preceded by \ and in quotations using `, ', and ". ๐Ÿ“

๐ŸŒˆ Commands ๐ŸŒˆ

A simple command is a sequence of words, the first of which specifies the command to be executed. A simple command or a sequence of simple commands separated by | characters forms a pipeline. The output of each command in a pipeline is connected to the input of the next. Sequences of pipelines may be separated by ;, and are then executed sequentially. A sequence of pipelines may be executed without immediately waiting for it to terminate by following it with a &. ๐Ÿ”—

Any of the above may be placed in ( ) to form a simple command (that may be a component of a pipeline, for example). It is also possible to separate pipelines with || or && showing, as in the C language, that the second is to be executed only if the first fails or succeeds, respectively. (See Expressions.) ๐Ÿง 

๐Ÿ‘‘ 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 that looks like:

[1] 1234

showing 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 ^Z (control-Z), which sends a SIGSTOP signal to the current job. The shell will then normally show that the job has been โ€œStoppedโ€, and print another prompt. You can then manipulate the state of this job, putting it in the background with the bg command, or run some other commands and eventually bring the job back into the foreground with the fg command. A ^Z takes effect immediately and is like an interrupt in that pending output and unread input are discarded when it is typed. There is another special key ^Y that does not generate a SIGSTOP signal until a program attempts to read(2) it. This request can usefully be typed ahead when you have prepared some commands for a job that you wish to stop after it has read them. โธ๏ธ

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

There are several ways to refer to jobs in the shell. The character % introduces a job name. If you wish to refer to job number 1, you can name it as %1. Just naming a job brings it to the foreground; thus %1 is a synonym for fg %1, bringing job number 1 back into the foreground. Similarly, saying %1 & resumes job number 1 in the background. Jobs can also be named by prefixes of the string typed in to start them, if these prefixes are unambiguous; thus %ex would normally restart a suspended ex(1) job, if there were only one suspended job whose name began with the string "ex". It is also possible to say %?string, which specifies a job whose text contains string, if there is only one such job. ๐Ÿ”

The shell maintains a notion of the current and previous jobs. In output about jobs, the current job is marked with a + and the previous job with a -. The abbreviation %+ refers to the current job and %- refers to the previous job. For close analogy with the syntax of the history mechanism (described below), %% is also a synonym for the current job. โž•โž–

The job control mechanism requires that the stty(1) option new be set. It is an artifact from a new implementation of the tty driver that allows generation of interrupt characters from the keyboard to tell jobs to stop. See stty(1) for details 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 just before it prints a prompt. This is done so that it does not otherwise disturb your work. If, however, you set the shell variable notify, the shell will notify you immediately of changes of status in background jobs. There is also a shell command notify that marks a single process so that its status changes will be immediately reported. By default notify marks the current process; simply say notify after starting a background job to mark it. ๐Ÿ””

When you try to leave the shell while jobs are stopped, you will be warned that โ€œYou have stopped jobsโ€. You may use the jobs command to see what they are. If you try to exit again immediately, the shell will not warn you a second time, and the suspended jobs will be terminated. โš ๏ธ

๐Ÿงš File name completion ๐Ÿงš

When the file name completion feature is enabled by setting the shell variable filec (see set), csh will interactively complete file names and user names from unique prefixes when they are input from the terminal followed by the escape character (the escape key, or control-[). For example, if the current directory looks like

the directory list is:

DSC.OLD  bin      cmd      lib      xmpl.c
DSC.NEW  chaosnet cmtest   mail     xmpl.o
bench    class    dev      mbox     xmpl.out

and the input is

% vi ch<escape>

csh will complete the prefix ch to the only matching file name chaosnet, changing the input line to

% vi chaosnet

However, given

% vi D<escape>

csh will only expand the input to

% vi DSC.

and will sound the terminal bell to indicate that the expansion is incomplete, since there are two file names matching the prefix D.

If a partial file name is followed by the end-of-file character (usually control-D), then, instead of completing the name, csh will list all file names matching the prefix. For example, the input

% vi D<control-D>

causes all files beginning with D to be listed:

DSC.NEW   DSC.OLD

while the input line remains unchanged.

The same system of escape and end-of-file can also be used to expand partial user names, if the word to be completed (or listed) begins with the tilde character (~). For example, typing

cd ~ro<escape>

may produce the expansion

cd ~root

The use of the terminal bell to signal errors or multiple matches can be inhibited by setting the variable nobeep.

Normally, all files in the particular directory are candidates for name completion. Files with certain suffixes can be excluded from consideration by setting the variable fignore to the list of suffixes to be ignored. Thus, if fignore is set by the command

% set fignore = (.o .out)

then typing

% vi x<escape>

would result in the completion to

% vi xmpl.c

ignoring the files "xmpl.o" and "xmpl.out". However, if the only completion possible requires not ignoring these suffixes, then they are not ignored. In addition, fignore does not affect the listing of file names by control-D. All files are listed regardless of their suffixes.

โœจ Substitutions โœจ

We now describe the various transformations the shell performs on the input in the order in which they occur. yes bestie, order matters โ€” it's giving pipeline energy ๐Ÿ’…

History substitutions ๐Ÿ•ฐ๏ธ๐Ÿ’–

History substitutions place words from previous command input as portions of new commands, making it easy to repeat commands, repeat arguments of a previous command in the current command, or fix spelling mistakes in the previous command with little typing and a high degree of confidence. History substitutions begin with the character ! and may begin anywhere in the input stream (with the proviso that they do not nest). This ! may be preceded by a \ to prevent its special meaning; for convenience, a ! character is passed unchanged when it is followed by a blank, tab, newline, = or (. (History substitutions also occur when an input line begins with ^. This special abbreviation will be described later.) Any input line that contains history substitution is echoed on the terminal before it is executed as it would have been typed without history substitution.

Commands input from the terminal that consist of one or more words are saved on the history list. The history substitutions reintroduce sequences of words from these saved commands into the input stream. The size of the history list is controlled by the history variable; the previous command is always retained, regardless of the value of the history variable. Commands are numbered sequentially from 1.

For definiteness, consider the following output from the history command:

09  write michael
10  ex write.c
11  cat oldwrite.c
12  diff *write.c

The commands are shown with their event numbers. It is not usually necessary to use event numbers, but the current event number can be made part of the prompt by placing a ! in the prompt string.

With the current event 13 we can refer to previous events by event number !11, relatively as in !-2 (referring to the same event), by a prefix of a command word as in !d for event 12 or !wri for event 9, or by a string contained in a word in the command as in !?mic? also referring to event 9. These forms, without further change, simply reintroduce the words of the specified events, each separated by a single blank. As a special case, !! refers to the previous command; thus !! alone is a redo.

To select words from an event we can follow the event specification by a : and a designator for the desired words. The words of an input line are numbered from 0, the first (usually command) word being 0, the second word (first argument) being 1, etc. The basic word designators are:

  • 0 โ€” first (command) word
  • n โ€” n'th argument
  • ^ โ€” first argument; i.e., 1
  • $ โ€” last argument
  • % โ€” word matched by (immediately preceding) ?s? search
  • x-y โ€” range of words
  • -y โ€” abbreviates 0-y
  • * โ€” abbreviates ^-$, or nothing if only 1 word in event
  • x* โ€” abbreviates x-$
  • x- โ€” like x* but omitting word $

The : separating the event specification from the word designator can be omitted if the argument selector begins with a ^, $, *, -, or %. After the optional word designator, a sequence of modifiers can be placed, each preceded by a :. The following modifiers are defined:

  • h โ€” Remove a trailing pathname component, leaving the head.
  • r โ€” Remove a trailing .xxx component, leaving the root name.
  • e โ€” Remove all but the extension .xxx part.
  • s/l/r/ โ€” Substitute l for r.
  • t โ€” Remove all leading pathname components, leaving the tail.
  • & โ€” Repeat the previous substitution.
  • g โ€” Apply the change once on each word, prefixing the above; e.g., g&.
  • a โ€” Apply the change as many times as possible on a single word, prefixing the above. It can be used together with g to apply a substitution globally.
  • p โ€” Print the new command line but do not execute it.
  • q โ€” Quote the substituted words, preventing further substitutions.
  • x โ€” Like q, but break into words at blanks, tabs, and newlines.

Unless preceded by a g, the change is applied only to the first modifiable word. With substitutions, it is an error for no word to be applicable.

The left-hand side of substitutions are not regular expressions in the sense of the editors, but instead strings. Any character may be used as the delimiter in place of /; a \ quotes the delimiter into the l and r strings. The character & in the right-hand side is replaced by the text from the left. A \ also quotes &. A NULL l (//) uses the previous string either from an l or from a contextual scan string s in !?s\?. The trailing delimiter in the substitution may be omitted if a newline follows immediately as may the trailing ? in a contextual scan.

A history reference may be given without an event specification; e.g., !$. Here, the reference is to the previous command unless a previous history reference occurred on the same line in which case this form repeats the previous reference. Thus !?foo?^ !$ gives the first and last arguments from the command matching ?foo?.

A special abbreviation of a history reference occurs when the first non-blank character of an input line is a ^. This is equivalent to !:s^ providing a convenient shorthand for substitutions on the text of the previous line. Thus ^lb^lib fixes the spelling of lib in the previous command. Finally, a history substitution may be surrounded with { and } if necessary to insulate it from the characters that follow. Thus, after ls -ld ~paul we might do !{l}a to do ls -ld ~paula, while !la would look for a command starting with la.

Quotations with ' and " ๐Ÿ’ฌ

The quotation of strings by ' and " can be used to prevent all or some of the remaining substitutions. Strings enclosed in ' are prevented from any further interpretation. Strings enclosed in " may be expanded as described below.

In both cases the resulting text becomes (all or part of) a single word; only in one special case (see Command Substitution below) does a " quoted string yield parts of more than one word; ' quoted strings never do.

Alias substitution ๐Ÿช„

The shell maintains a list of aliases that can be established, displayed and modified by the alias and unalias commands. After a command line is scanned, it is parsed into distinct commands and the first word of each command, left-to-right, is checked to see if it has an alias. If it does, then the text that is the alias for that command is reread with the history mechanism available as though that command were the previous input line. The resulting words replace the command and argument list. If no reference is made to the history list, then the argument list is left unchanged.

Thus if the alias for ls is ls -l, the command ls /usr would map to ls -l /usr, the argument list here being undisturbed. Similarly, if the alias for lookup was grep !^ /etc/passwd then lookup bill would map to grep bill /etc/passwd.

If an alias is found, the word transformation of the input text is performed and the aliasing process begins again on the reformed input line. Looping is prevented if the first word of the new text is the same as the old by flagging it to prevent further aliasing. Other loops are detected and cause an error.

Note that the mechanism allows aliases to introduce parser metasyntax. Thus, we can alias print 'pr \!* | lpr' to make a command that pr's its arguments to the line printer.

Variable substitution ๐Ÿงฎ

The shell maintains a set of variables, each of which has as value a list of zero or more words. Some of these variables are 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.

The values of variables may be displayed and changed by using the set and unset commands. Of the variables referred to by the shell a number 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 that causes command input to be echoed. The setting of this variable results from the -v command-line option.

Other operations treat variables numerically. The @ command lets you do actual math and stash the result in a variable. But bestie, hear me โ€” variable values are always represented as (zero or more) strings. Always. For numeric ops though, the null string counts as zero, and the second and additional words of multiword values just get ignored. ๐Ÿ’…


After the input line is aliased and parsed, and before each command runs, variable substitution happens, keyed by โ€˜$โ€™ characters. You can block this expansion by putting a โ€˜\โ€™ before the โ€˜$โ€™ โ€” except inside double quotes (โ€˜"โ€™), where it always occurs, and inside single quotes (โ€˜'โ€™), where it never does. Strings quoted by backticks (` `) get interpreted later (peep โ€œCommand substitutionโ€ below ๐Ÿ‘€), so โ€˜$โ€™ substitution doesn't happen there until later, if at all. And a โ€˜$โ€™ is passed through untouched if it's followed by a blank, tab, or end-of-line.

Input/output redirections are recognized before variable expansion, and get variable expanded separately. Otherwise, the command name and the entire argument list expand together. So yeah โ€” it's possible for that first (command) word to generate more than one word, where the first becomes the command name and the rest become arguments. main character word energy, honestly. โœจ

Unless it's wrapped in โ€˜"โ€™ or given the โ€˜:qโ€™ modifier, the results of variable substitution may eventually get command and filename substituted. Within โ€˜"โ€™, a variable whose value is 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 expands to multiple words with each word separated by a blank and quoted to prevent later command or filename substitution. ๐ŸŽ€

The following metasequences are how you introduce variable values into shell input. Except as noted, it's an error to reference a variable that isn't set.

  • $name, ${name} โ€” replaced by the words of the value of variable name, each separated by a blank. Braces insulate name from following characters that would otherwise be part of it. Shell variables have names of up to 20 letters and digits starting with a letter โ€” and yeah, the underscore character counts as a letter. If name isn't a shell variable but is set in the environment, then that value is returned (but โ€˜:โ€™ modifiers and the other forms given below are not available here, sowwy ๐Ÿ™ˆ).
  • $name[selector], ${name[selector]} โ€” may be used to select only some of the words from the value of name. The selector is subjected to โ€˜$โ€™ substitution and may be 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 number 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. slay.
  • $#name, ${#name} โ€” gives the number of words in the variable. Super useful for later use in a โ€œ$argv[selector]โ€. ๐Ÿฆ‹
  • $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[*]โ€.

The modifiers โ€˜:eโ€™, โ€˜:hโ€™, โ€˜:tโ€™, โ€˜:rโ€™, โ€˜:qโ€™, and โ€˜:xโ€™ may be applied to the substitutions above, as may โ€˜:ghโ€™, โ€˜:gtโ€™, and โ€˜:grโ€™. If braces โ€˜{โ€™ โ€˜}โ€™ appear in the command form then the modifiers must appear within the braces. The current implementation allows only one โ€˜:โ€™ modifier on each โ€˜$โ€™ expansion. periodt.

The following substitutions may not 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.
  • $$ โ€” substitutes the (decimal) process number of the (parent) shell. Do NOT use this mechanism for generating temporary file names; see mktemp(1) instead. fr fr, use the real tool. ๐Ÿ’€
  • $! โ€” substitutes the (decimal) process number of the last background process started by this shell.
  • $< โ€” substitutes a line from the standard input, with no further interpretation. It can be used to read from the keyboard in a shell script. ๐Ÿ‘‘

โœจ Command and filename substitution โœจ

The remaining substitutions โ€” command and filename substitution โ€” are applied selectively to the arguments of built-in commands. By selectively, we mean that portions of expressions which are not evaluated are not subjected to these expansions. For commands that aren't internal to the shell, the command name is substituted separately from the argument list. This happens very late, after input-output redirection is performed, and in a child of the main shell. the way it waits until the last possible secondโ€ฆ iconic ๐ŸŒธ

๐Ÿ’ซ Command substitution ๐Ÿ’ซ

Command substitution is shown by a command enclosed in โ€˜`โ€™. The output from such a command is normally broken into separate words at blanks, tabs, and newlines, with null words being discarded; this text then replaces the original string. Within double quotes (โ€˜"โ€™), only newlines force new words; blanks and tabs are preserved.

In any case, the single final newline does not force a new word. Note that it is thus possible for a command substitution to yield only part of a word, even if the command outputs a complete line. sneaky but valid ๐Ÿ˜Œ

๐Ÿงš Filename substitution ๐Ÿงš

If a word contains any of the characters โ€˜*โ€™, โ€˜?โ€™, โ€˜[โ€™, or โ€˜{โ€™, or begins with the character โ€˜~โ€™, then that word is a candidate for filename substitution, also known as โ€œglobbingโ€. That word is then regarded as a pattern, and replaced with an alphabetically sorted list of file names that match the pattern. In a list of words specifying filename substitution it is an error for no pattern to match an existing file name, but it is not required for each pattern to match. Only the metacharacters โ€˜*โ€™, โ€˜?โ€™, and โ€˜[โ€™ imply pattern matching โ€” the characters โ€˜~โ€™ and โ€˜{โ€™ are more akin to abbreviations. ๐Ÿ’…

In matching filenames, the character โ€˜.โ€™ at the beginning of a filename or immediately following a โ€˜/โ€™, as well as the character โ€˜/โ€™ itself, must be matched explicitly. The character โ€˜*โ€™ matches any string of characters, including the null string. The character โ€˜?โ€™ matches any single character.

The sequence โ€œ[...]โ€ matches any one of the characters enclosed. Within โ€œ[...]โ€, a pair of characters separated by โ€˜-โ€™ matches any character lexically between the two (inclusive). Within โ€œ[...]โ€, the name of a character class enclosed in โ€˜[:โ€™ and โ€˜:]โ€™ stands for the list of all characters belonging to that class. Supported character classes:

alnum   cntrl   lower   space
alpha   digit   print   upper
blank   graph   punct   xdigit

These match characters using the macros specified in isalnum(3), isalpha(3), and so on. A character class may not be used as an endpoint of a range. no cap, that's just how it is ๐Ÿซถ

The character โ€˜~โ€™ at the beginning of a filename refers to home directories. Standing alone, i.e., โ€˜~โ€™, it expands to the invoker's home directory as reflected in the value of the variable home. When followed by a name consisting of letters, digits, and โ€˜-โ€™ characters, the shell searches for a user with that name and substitutes their home directory; thus โ€œ~kenโ€ might expand to โ€œ/usr/kenโ€ and โ€œ~ken/chmachโ€ to โ€œ/usr/ken/chmachโ€. If the character โ€˜~โ€™ is followed by a character other than a letter or โ€˜/โ€™, or does not appear at the beginning of a word, it is left undisturbed. lowkey polite of it โœจ

The metanotation โ€œa{b,c,d}eโ€ is a shorthand for โ€œabe ace adeโ€. Left to right order is preserved, with results of matches being sorted separately at a low level to preserve this order. This construct may be nested. Thus, โ€œ~source/s1/{oldls,ls}.cโ€ expands to โ€œ/usr/source/s1/oldls.c /usr/source/s1/ls.cโ€ without chance of error if the home directory for โ€œsourceโ€ is โ€œ/usr/sourceโ€. Similarly โ€œ../{memo,*box}โ€ might expand to โ€œ../memo ../box ../mboxโ€. (Note that โ€œmemoโ€ was not sorted with the results of the match to โ€œ*boxโ€.) As a special case โ€˜{โ€™, โ€˜}โ€™, and โ€˜{}โ€™ are passed undisturbed. ๐Ÿ‘‘

๐ŸŒˆ Input/output ๐ŸŒˆ

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

  • < name โ€” open file name (which is first variable, command, and filename expanded) as the standard input.
  • << word โ€” read the shell input up to a line that is identical to word. word is not subjected to variable, command, or filename substitution, and each input line is compared to word before any substitutions are done on the input line. Unless a quoting โ€˜\โ€™, โ€˜"โ€™, โ€˜'โ€™ or โ€˜`โ€™ appears in word, variable and command substitution is performed on the intervening lines, allowing โ€˜\โ€™ to quote โ€˜$โ€™, โ€˜\โ€™ and โ€˜`โ€™. Commands that 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 that is given to the command as its standard input. ๐Ÿ“
  • > name, >! name, >& name, >&! name โ€” the file name is used as the standard output. If the file does not exist then it is created; if the file exists, it is truncated; its previous contents are lost. ๐Ÿ’€

If the 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. Here, the โ€˜!โ€™ forms can be used to suppress this check. use them wisely bestie, they're the little "i know what i'm doing" button ๐Ÿ”ฅ

The forms with & in them send the standard error output into the same file as the standard output, bestie โ€” two streams, one destination. And name gets expanded exactly like < input filenames do, no cap. ๐Ÿ’…

  • >> name โ€” Uses name as the standard output, like > but it drops the output at the end of the file instead of wiping it. If the variable noclobber is set, then it's an error for the file to not exist, unless you use one of the ! forms. Otherwise it behaves like >.
  • >>& name โ€” same as >> but standard error comes along for the ride.
  • >>! name โ€” the ! version, so noclobber can't ruin your day.
  • >>&! name โ€” both at once: append, stderr included, noclobber overridden.

A command inherits the environment the shell was invoked in, tweaked by all your input-output parameters and by where the command sits in a pipeline. So โ€” and this is the plot twist โ€” unlike some older shells, commands run from a file of shell commands don't get access to the text of those commands by default. Nope. They receive the shell's original standard input instead. If you want inline data, use the << mechanism. This is what lets shell command scripts function as components of pipelines, and it lets the shell block-read its input. ๐Ÿซถ

Also important: the default standard input for a command run detached is not modified to be the empty file /dev/null. It stays as the shell's original standard input. And if that's a terminal, and the process tries to read from it, the process will block and the user gets notified (see "Jobs" above). ๐Ÿ’€

You can also send the standard error output through a pipe together with the standard output. Just use |& instead of plain |. That's it, that's the trick. โœจ

๐ŸŒˆ Expressions ๐ŸŒˆ

A bunch of the built-in commands (we'll get to them, patience ๐Ÿ’–) take expressions. The operators are like C's, with the same precedence โ€” but the grouping goes the opposite way: right to left. Iconic, honestly. These expressions show up in the @, exit, if, and while commands. Here's the full roster:

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

Precedence increases as you go right. Grouped at the same level: == != =~ and !~; then <= >= < and >; then << and >>; then + and -; then * / and %.

The == != =~ and !~ operators compare their arguments as strings. Everything else works on numbers. And =~ and !~ are like != and == respectively โ€” except the right-hand side is a pattern (think *'s, ?'s, and instances of [...]) that the left-hand operand gets matched against. Which means you need the switch statement way less in your shell scripts when all you actually wanted was pattern matching. Slay. ๐ŸŽ€

Strings starting with 0 are read as octal numbers. Null or missing arguments count as 0. Every expression's result is a string representing a decimal number. And here's the one that bites people: no two components of an expression can appear in the same word. Unless they're adjacent to components that are syntactically significant to the parser (&, |, <, >, (, and )), you gotta put spaces around them. Surround. Your. Tokens. ๐Ÿซถ

You can also use command executions wrapped in { and } as primitive operands in expressions, plus file enquiries of the form -l name, where l is one of these little legends:

  • r โ€” read access
  • w โ€” write access
  • x โ€” execute access
  • e โ€” existence
  • o โ€” ownership
  • z โ€” zero size
  • f โ€” plain file
  • d โ€” directory
  • p โ€” named pipe (FIFO)
  • l โ€” symbolic link

That name gets command-and-filename expanded, then tested to see whether it has the specified relationship to the real user. If the file doesn't exist or is inaccessible, every enquiry returns false, i.e. 0. Command executions succeed and return true, i.e. 1, if the command exits with status 0 โ€” otherwise they fail and return false, i.e. 0. Want more detailed status info? Run the command outside an expression and go check the variable status. ๐Ÿ’…

๐Ÿฆ‹ Control flow ๐Ÿฆ‹

The shell has several commands for regulating the flow of control in command files (shell scripts) and โ€” in limited but genuinely useful ways โ€” from terminal input. They all work by forcing the shell to reread or skip around in its input, and because of how that's implemented, some of these commands can only live in certain places. Location matters, bestie.

The foreach, switch, and while statements, plus the if-then-else form of the if statement, all require their major keywords to appear in a single simple command on an input line, exactly as shown below.

If the shell's input isn't seekable, the shell buffers up input whenever a loop is being read and does seeks inside that internal buffer to pull off the rereading the loop implies. (To the extent that this allows, backward goto's will succeed on non-seekable inputs.) Lowkey clever. โœจ

๐Ÿ‘‘ Built-in commands ๐Ÿ‘‘

Built-in commands run inside the shell. And heads up: if a built-in command shows up as any component of a pipeline except the last one, it's executed in a sub-shell. Noted. ๐Ÿ“

  • alias
  • alias name
  • alias name wordlist โ€” The first form prints every alias. The second prints the alias for name. The final form assigns the given wordlist as the alias of name; wordlist gets command and filename substituted. Oh, and name is not allowed to be alias or unalias. Sorry babe, those are taken. ๐Ÿ™ˆ
  • bg
  • bg %job ... โ€” Puts the current or specified jobs into the background, continuing them if they were stopped.
  • break โ€” Causes execution to resume after the end of the nearest enclosing foreach or while. The remaining commands on the current line are executed. So multi-level breaks are possible โ€” you just write them all on one line. Combo move. ๐Ÿ”ฅ
  • breaksw โ€” Causes a break from a switch, resuming after the endsw.
  • case label: โ€” A label in a switch statement, as discussed below.
  • cd
  • cd name
  • chdir
  • chdir name โ€” Changes the shell's working directory to directory name. No argument? You go to the user's home directory. If name isn't found as a subdirectory of the current directory (and doesn't begin with /, ./ or ../), then each component of the variable cdpath gets checked to see if it has a subdirectory name. And finally, if all else fails but name is a shell variable whose value begins with /, then that gets tried to see if it's a directory. Persistence! ๐Ÿ’ช
  • continue โ€” Continues execution of the nearest enclosing while or foreach. The rest of the commands on the current line are executed.
  • default: โ€” Labels the default case in a switch statement. It should come after all the case labels. Order matters, babes.
  • dirs โ€” Prints the directory stack; the top of the stack is on the left, and the first directory in the stack is the current directory.
  • echo wordlist
  • echo -n wordlist โ€” The specified words get written to the shell's standard output, separated by spaces, and terminated with a newline โ€” unless you pass -n, in which case, no newline. Simple as. โœจ
  • else
  • end
  • endif
  • endsw โ€” See the descriptions of the foreach, if, switch, and while statements below.
  • eval arg ... โ€” (Same as in sh(1).) The arguments are read as input to the shell, and the resulting command(s) are executed in the context of the current shell. This is usually used to execute commands generated as the result of command or variable substitution, since parsing happens before those substitutions. See tset(1) for an example of using eval. ๐Ÿงš
  • exec command โ€” The specified command is executed in place of the current shell. No going back.
  • exit
  • exit (expr) โ€” The shell exits with the value of the status variable (first form) or with the value of the specified expr (second form). Bye bestie ๐Ÿ‘‹
  • fg
  • fg %job ... โ€” Brings the current or specified jobs into the foreground, continuing them if they were stopped.
  • foreach name (wordlist)
  • ...
  • end โ€” The variable name gets successively set to each member of wordlist, and the sequence of commands between this command and the matching end gets executed. (Both foreach and end must appear alone on separate lines โ€” no sneaking extra stuff on those lines.) The built-in continue can continue the loop prematurely, and the built-in break can terminate it prematurely. When this command is read from the terminal, the loop is read once, prompting with ? before any statements in the loop are executed. And if you mess up typing in a loop at the terminal, you can rub it out. ๐Ÿ˜Œ
  • glob wordlist โ€” Like echo, but no \ escapes are recognized and words are delimited by NUL characters in the output. Useful for programs that want to use the shell to filename-expand a list of words.
  • goto word โ€” The specified word is filename and command expanded to yield a string of the form label. The shell rewinds its input as much as possible and searches for a line of the form "label:", possibly preceded by blanks or tabs. Execution continues after the specified line. ๐ŸŒ€
  • hashstat โ€” Prints a statistics line showing 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 that does not begin with a /. ๐Ÿ“Š

โœจ history โœจ

history
history n
history -h n
history -r n

okay so history shows you the history event list โ€” the whole receipts of your session ๐Ÿ’…. Hand it an n and it only prints the n most recent events, so you're not scrolling through your entire past to find one thing.

-h causes the history list to be printed without leading numbers. why do you care? because this format produces files suitable for sourcing using the -h option to source. cute little pipeline moment ๐ŸŽ€.

-r reverses the order of printout to be most recent first instead of oldest first. reverse chronological, main character energy, no notes.


โœจ if โœจ

two flavors, bestie, and they hit different.

if (expr) command

If the specified expression evaluates to true, then the single command with arguments is executed. Variable substitution on command happens early, at the same time it does for the rest of the if command.

here's the tea though: command must be a simple command โ€” not a pipeline, a command list, or a parenthesized command list. and input/output redirection occurs even if expr is false, i.e., when command is not executed (this is a bug). not me exposing a bug in the manpage itself ๐Ÿ™ˆ.
if (expr) then
...
else if (expr2) then
...
else
...
endif

If the specified expr is true then the commands up to the first else are executed; otherwise if expr2 is true then the commands up 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.)

โœจ jobs โœจ

jobs
jobs -l

Lists the active jobs. The -l option lists process IDs in addition to the normal information. so you get the pids too, iconic ๐Ÿ‘‘


โœจ kill โœจ

kill %job
kill [-s signal_name] pid
kill -sig pid ...
kill -l [exit_status]

Sends either the SIGTERM (terminate) signal or the specified signal to the specified jobs or processes. Signals are either given by number or by names (as given in <signal.h>, stripped of the prefix "SIG"). The signal names are listed by kill -l; if an exit_status is specified, only the corresponding signal name will be written.

There is no default; just saying kill does not send a signal to the current job. no vibes-based killing, you have to be specific fr fr ๐Ÿ’€.

If the signal being sent is SIGTERM (terminate) or SIGHUP (hangup), then the job or process will be sent a SIGCONT (continue) signal as well.


โœจ limit โœจ

limit
limit resource
limit resource maximum-use
limit -h
limit -h resource
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.

No maximum-use? then the current limit is printed. No resource? then all limitations are given. With the -h flag, 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 superuser may raise the hard limits, but a user may lower or raise the current limits within the legal range.

Resources controllable currently include:

  • cputime โ€” the maximum number of CPU-seconds to be used by each process.
  • filesize โ€” the largest single file (in bytes) that can be created.
  • datasize โ€” the maximum growth (in bytes) of the data segment.
  • stacksize โ€” the maximum size of the automatically-extended stack region.
  • coredumpsize โ€” the size of the largest core dump (in bytes) that will be created.
  • memoryuse โ€” the maximum size (in bytes) to which a process's resident set size (RSS) may grow. Not enforced.
  • memorylocked โ€” The maximum size (in bytes) which a process may lock into memory using the mlock(2) function.
  • maxproc โ€” The maximum number of simultaneous processes for this user ID.
  • openfiles โ€” The maximum number of simultaneous open files for this user ID.
  • vmemoryuse โ€” the maximum size (in bytes) to which a process's total size may grow.

The maximum-use may be given as a (floating point or integer) number followed by a scale factor. For all limits other than cputime the default scale is 'k' or "kilobytes" (1024 bytes); a scale factor of 'm' or "megabytes" may also be used. For cputime the default scale is "seconds"; a scale factor of 'm' for minutes or 'h' for hours, or a time of the form "mm:ss" giving minutes and seconds also may be used.

For both resource names and scale factors, unambiguous prefixes of the names suffice. so you can be lazy, the shell will figure it out ๐Ÿฆ‹.


โœจ login โœจ

Terminate a login shell, replacing it with an instance of /usr/bin/login. This is one way to log off, included for compatibility with sh(1).


โœจ logout โœจ

Terminate a login shell. Especially useful if ignoreeof is set. the classic "i'm done here" move ๐Ÿ’–.


โœจ nice โœจ

nice
nice +number
nice command
nice +number command

The first form sets the scheduling priority for this shell to 4. The second form sets the priority to the given number. The final two forms run command at priority 4 and number respectively.

The greater the number, the less CPU the process will get. The superuser may specify negative 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 โœจ

nohup
nohup command

The first form can be used in shell scripts to cause hangups to be ignored for the remainder of the script. The second form causes the specified command to be run with hangups ignored.

All processes detached with & are effectively nohup'ed. iykyk โœจ


โœจ notify โœจ

notify
notify %job ...

Causes the shell to notify the user asynchronously when the status of the current or specified jobs change; normally notification is presented before a prompt. This is automatic if the shell variable notify is set.


โœจ onintr โœจ

onintr
onintr -
onintr label

Control the action of the shell on interrupts. The first form restores the default action of the shell on interrupts, which is to terminate shell scripts or to return to the terminal command input level. The second form onintr - causes all interrupts to be ignored. The final form causes the shell to execute a goto label when an interrupt is received or a child process terminates because it was interrupted.

In any case, if the shell is running detached and interrupts are being ignored, all forms of onintr have no meaning and interrupts continue to be ignored by the shell and all invoked commands.

Finally, onintr statements are ignored in the system startup files where interrupts are disabled (/etc/csh.cshrc, /etc/csh.login).


โœจ popd โœจ

popd
popd +n

Pops the directory stack, returning to the new top directory. With an argument +n discards the n'th entry in the stack. The members of the directory stack are numbered from the top starting at 0.


โœจ pushd โœจ

pushd
pushd name
pushd +n

With no arguments, pushd exchanges the top two elements of the directory stack. Given a name argument, pushd changes to the new directory (ala cd) and pushes the old current working directory (as in cwd) onto the directory stack. With a numeric argument, pushd rotates the n'th argument of the directory stack around to be the top element and changes to it. The members of the directory stack are numbered from the top starting at 0.


โœจ rehash โœจ

Causes the internal hash table of the contents of the directories in the path variable to be recomputed. This is needed if new commands are added to directories in the path while you are logged in. This should only be necessary if you add commands to one of your own directories, or if a systems programmer changes the contents of a system directory.


โœจ repeat โœจ

repeat count command

The specified command, which is subject to the same restrictions as the command in the one line if statement above, is executed count times. I/O redirections occur exactly once, even if count is 0. even zero times, the redirection still happened, periodt ๐Ÿ’…


โœจ set โœจ

set
set name
set name=word
set name[index]=word
set name=(wordlist)

The first form of the command shows the value of all shell variables. Variables that have other than a single word as their value print as a parenthesized word list.

The second form sets name to the null string. The third form sets name to the single word. The fourth form sets the index'th component of name to word; this component must already exist. The final form sets name to the list of words in wordlist.

The value is always command and filename expanded.

These arguments may be repeated to set multiple values in a single set command. Note however, that variable expansion happens for all arguments before any setting occurs. so like, don't expect your second arg to see what your first arg just did ๐Ÿซถ


  • setenv / setenv name / setenv name value
    • first form: dumps every single environment variable you've got rn. literally the same thing as printenv(1), no cap.
    • second form: sets name to an empty string. a little blank-slate moment.
    • third form: sets environment variable name to value โ€” one single string, that's it, that's the whole assignment.
    • okay bestie hear me: the big three โ€” USER, TERM and PATH โ€” get auto-imported and auto-exported to the csh variables user, term and path. so you genuinely do not need setenv for those. they're already handled ๐Ÿ’…
  • shift / shift variable
    • shuffles the members of argv to the left and just drops argv[1] into the void ๐Ÿ•ณ๏ธ
    • it's an error if argv isn't set, or if its value has fewer than one word.
    • second form does the exact same glow-up to whichever variable you name.
  • source name / source -h name
    • shell reads commands straight out of name. very "run this script, bestie."
    • source commands can be nested โ€” but if you nest them too deep, the shell may legitimately run out of file descriptors ๐Ÿ˜ญ
    • an error in a source at any level terminates all nested source commands. it's giving domino effect.
    • normally, input during source commands does not get put on the history list. the -h option puts the commands on the history list without executing them โ€” a little โœจsave for laterโœจ situation.
  • stop / stop %job ...
    • stops the current job, or the specific jobs you name, that are chugging along in the background. nap time ๐Ÿ›‘
  • suspend
    • makes the shell stop in its tracks, exactly like it got sent a stop signal with ^Z. most often used to stop shells that were started by su(1). iconic little freeze-frame.
  • switch (string) โ€” with case, default, breaksw, endsw:
    • every case label gets matched against the given string, one after another, and that string is first command- and filename-expanded.
    • the file metacharacters '*', '?' and "[...]" are allowed in the case labels, and those labels are variable expanded.
    • if nothing matches before the default label shows up, execution starts after the default label.
    • every case label and the default label must appear at the beginning of a line. non-negotiable.
    • breaksw makes execution continue after the endsw. otherwise control can fall through case labels and the default label, just like in C.
    • if no label matches and there's no default? execution just continues after the endsw. keep it moving ๐Ÿšถโ€โ™€๏ธ
switch (string)
case str1:
    ...
    breaksw
    ...
default:
    ...
    breaksw
endsw
  • time / time command
    • no arguments? you get a summary of the time used by this shell and its children. a lil recap ๐ŸŽ€
    • arguments given? the specified simple command gets timed, and a time summary as described under the time variable gets printed.
    • if it's necessary, an extra shell is created just to print that time statistic when the command completes.
  • umask / umask value
    • first form displays the file creation mask, second form sets it to value.
    • the mask is given in octal. common values: 002 gives all access to the group plus read and execute access to others, or 022 gives all access except write access for users in the group or others.
    • chmod(2) has the complete list of bits you can set, so go read that if you want the full menu.
  • unalias pattern
    • throws away all aliases whose names match pattern. so unalias * nukes every alias you own ๐Ÿ’€
    • it is not an error for nothing to be unaliased. no drama.
  • unhash
    • disables use of the internal hash table that speeds up finding executed programs. so long, shortcut โœŒ๏ธ
  • unlimit / unlimit resource / unlimit -h / unlimit -h resource
    • removes the limitation on resource.
    • no resource specified? all resource limitations get removed.
    • -h given? the corresponding hard limits get removed.
    • only the superuser may do this. ๐Ÿ‘‘
  • unset pattern
    • removes all variables whose names match pattern. so unset * removes every variable โ€” and that has noticeably distasteful side-effects. you have been warned.
    • it is not an error for nothing to be unset.
  • unsetenv pattern
    • removes all variables whose names match pattern from the environment.
    • see also setenv above and printenv(1).
  • wait
    • waits for all background jobs. patience, bestie ๐Ÿง˜โ€โ™€๏ธ
    • if the shell is interactive, an interrupt can disrupt the wait.
    • after the interrupt, the shell prints the names and job numbers of all jobs it knows are still outstanding.
  • which command
    • displays the resolved command that the shell will actually execute. the โœจtruth revealโœจ.
  • while (expr) โ€ฆ end
    • while the given expression evaluates to non-zero, the commands between the while and the matching end get evaluated.
    • break and continue can terminate or continue the loop early.
    • the while and the end must appear alone on their input lines.
    • prompting happens here the first time through the loop, same as for the foreach statement, if the input is a terminal.
  • %job
    • brings the specified job into the foreground. main character energy, front and center ๐Ÿ‘‘
  • %job &
    • continues the specified job in the background.
  • @ / @ name=expr / @ name[index]=expr
    • first form prints the values of all the shell variables.
    • second form sets name to the value of expr. if the expression contains '<', '>', '&' or '|', then at least that part of the expression must be wrapped in '(' ')'.
    • third form assigns the value of expr to the index'th argument of name. both name and its index'th component must already exist.
    • the operators '*=', '+=', etc. are available, just like in C.
    • the space separating the name from the assignment operator is optional. spaces are, however, mandatory when separating components of expr โ€” otherwise it'd just be one single word.
    • the special postfix '++' and '--' operators increment and decrement name respectively; i.e., "@ i++".

๐ŸŒˆ Pre-defined and environment variables ๐ŸŒˆ

The following variables have special meaning to the shell. Of these, argv, cwd, home, path, prompt, shell and status are always set by the shell. Except for cwd and status, this setting happens only at initialization โ€” so those variables won't get modified afterwards unless the user explicitly does it.

The shell copies the environment variable USER into the variable user, TERM into term, and HOME into home, and copies these back into the environment whenever the normal shell variables are reset. The environment variable PATH is handled the same way; you don't need to worry about its setting anywhere other than in the file .cshrc, because inferior csh processes will import the definition of path from the environment, and re-export it if you then change it. ๐Ÿซถ

  • argv โ€” set to the arguments to the shell; it's from this variable that positional parameters get substituted, i.e. "$1" is replaced by "$argv[1]", etc.
  • cdpath โ€” gives a list of alternate directories searched to find subdirectories in chdir commands.
  • cwd โ€” the full pathname of the current directory.
  • echo โ€” set when the -x command-line option is given. causes each command and its arguments to be echoed just before it's executed. for non-built-in commands, all expansions happen before echoing. built-in commands are echoed before command and filename substitution, since these substitutions are then done selectively.
  • filec โ€” enables file name completion. โœจ
  • histchars โ€” can be given a string value to change 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.
  • histfile โ€” can be set to the pathname where history is going to be saved/restored.
  • history โ€” can be given a numeric value to control the size of the history list. any command that has been referenced in this many events will not be discarded. too large values of history may run the shell out of memory ๐Ÿ˜ญ. the last executed command is always saved on the history list.
  • home โ€” the home directory of the invoker, initialized from the environment. the filename expansion of "~" refers to this variable.
  • ignoreeof โ€” if set, the shell ignores end-of-file from input devices which are terminals. this prevents shells from accidentally being killed by control-Ds. a little safety rail ๐Ÿ’–
  • mail โ€” the files where the shell checks for mail. this checking happens after each command completion that will result in a prompt, if a specified interval has elapsed. the shell says "You have new mail." if the file exists with an access time not greater than its modify time.
    • if the first word of the value of mail is numeric, it specifies a different mail checking interval, in seconds, than the default, which is 10 minutes.
    • if multiple mail files are specified, then the shell says "New mail in name" when there's mail in the file name.
  • noclobber โ€” as described in the section on "Input/output", restrictions are placed on output redirection to ensure files aren't accidentally destroyed, and that '>>' redirections refer to existing files.
  • noglob โ€” if set, filename expansion is inhibited. this inhibition is most useful in shell scripts that aren't dealing with filenames, or after a list of filenames has been obtained and further expansions are not desirable.
  • nonomatch โ€” set this and a filename expansion that matches, like, zero existing files stops being an error ๐Ÿ’… instead you just get the primitive pattern handed right back to you. It's still an error if the primitive pattern itself is malformed though โ€” so echo [ still gives an error, no cap.
  • notify โ€” set it and the shell pings you about job completions asynchronously, like a lil notification sliding in mid-thought ๐Ÿฆ‹. The default vibe is way more chill: job completions get presented just before it prints a prompt.
  • path โ€” every single word in this variable names a directory where commands get looked up so they can be executed. A null word means the current directory. And if there's no path variable at all? Then only full path names will execute, periodt. The usual search path is ., /bin, /usr/bin, /sbin and /usr/sbin, but bestie, that may vary from system to system. For the superuser ๐Ÿ‘‘ the default search path is /bin, /usr/bin, /sbin, and /usr/sbin. A shell that's given neither the -c nor the -t option will normally hash the contents of the directories in the path variable after reading .cshrc, and again each time the path variable is reset. If new commands get added to those directories while the shell is still active, it may be necessary to do a rehash or the commands may not be found ๐Ÿ˜ญ.
  • prompt โ€” the string printed before each command is read from an interactive terminal input. If a ! appears in the string, it gets replaced by the current event number โ€” unless a preceding \ is given. Default is the first part of the hostname, followed by %, or # for the superuser โœจ.
  • savehist โ€” you give it a numeric value and it controls how many entries of the history list get saved in ~/.history when the user logs out. Any command that has been referenced in this many events will be saved. During start up the shell sources ~/.history into the history list, which is the whole reason history can be saved across logins ๐Ÿซถ. Warning though: too large values of savehist will slow down the shell during start up. And if savehist is just set (no number, just vibes), the shell will use the value of history.
  • shell โ€” the file in which the shell resides. This variable is used in forking shells to interpret files that have execute bits set, but which are not executable by the system. (See the description of โ€œNon-built-in command executionโ€ below, bestie.) Initialized to the (system-dependent) home of the shell.
  • status โ€” the status returned by the last command. If it terminated abnormally, then 0200 is added to the status. Built-in commands that fail return exit status 1, all other built-in commands set status to 0. ๐Ÿ“
  • time โ€” controls automatic timing of commands. If set, then any command that takes more than this many CPU seconds will cause a line giving user, system, and real times, and a utilization percentage โ€” which is the ratio of user plus system times to real time โ€” to be printed when it terminates. It's giving stopwatch energy โฑ๏ธ.
  • verbose โ€” set by the -v command-line option, and it causes the words of each command to be printed after history substitution.

๐ŸŒˆ Non-built-in command execution ๐ŸŒˆ

So when a command that's about to be executed turns out to not be a built-in command, the shell attempts to execute the command via execve(2). Each word in the variable path names a directory from which the shell will attempt to execute the command. If it's given neither a -c nor a -t option, the shell will hash the names in these directories into an internal table so that it will only try an exec in a directory if there's a possibility that the command resides there. That shortcut greatly speeds up command location when there are many directories present in the search path ๐Ÿ”ฅ.

If this mechanism has been turned off (via unhash), or if the shell was given a -c or -t argument, and in any case for each directory component of path that does not begin with a /, the shell concatenates with the given command name to form a path name of a file which it then attempts to execute.

Parenthesized commands are always executed in a sub-shell. So like:

(cd; pwd); pwd

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 chdir from affecting the current shell. iykyk ๐Ÿงš

If the file has execute permissions but is not an executable binary to the system, then it is assumed to be a file containing shell commands and a new shell is spawned to read it.

If there is an alias for shell then the words of the alias will be prepended to the argument list to form the shell command. The first word of the alias should be the full path name of the shell (e.g., $shell). Note that this is a special, late occurring, case of alias substitution, and it only allows words to be prepended to the argument list without change.


๐Ÿšฆ Signal handling ๐Ÿšฆ

The shell normally ignores SIGQUIT signals. Jobs running detached (either by & or the bg or %... & commands) are immune to signals generated from the keyboard, including hangups ๐Ÿ’€. Other signals have the values which the shell inherited from its parent. The shell's handling of interrupts and terminate signals in shell scripts can be controlled by onintr. Login shells catch the SIGTERM (terminate) signal; otherwise this signal is passed on to children from the state in the shell's parent. And heads up: interrupts are not allowed when a login shell is reading the file .logout.


๐Ÿ’€ LIMITATIONS ๐Ÿ’€

Word lengths: words can be no longer than 1024 characters. The number of arguments to a command that 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. And to detect looping, the shell restricts the number of alias substitutions on a single line to 20. ๐Ÿซ 


๐Ÿ“ FILES ๐Ÿ“

  • ~/.cshrc โ€” read at beginning of execution by each shell
  • ~/.login โ€” read by login shell, after .cshrc at login
  • ~/.logout โ€” read by login shell, at logout
  • /bin/sh โ€” standard shell, for shell scripts not starting with a #
  • /tmp/sh.* โ€” temporary file for <<
  • /etc/passwd โ€” source of home directories for ~name

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

ksh(1), sh(1), tty(4), environ(7), script(7)

W. Joy, An Introduction to the C shell.


๐Ÿ“œ HISTORY ๐Ÿ“œ

csh first appeared in 2BSD. It was a first implementation of a command language interpreter incorporating a history mechanism (see โ€œHistory substitutionsโ€), job control facilities (see โ€œJobsโ€), interactive file name and user name completion (see โ€œFile name completionโ€), and a C-like syntax. There are now many shells that also have these mechanisms, plus a few more (and maybe some bugs too), which are available through the usenet. iconic lineage honestly ๐Ÿ‘‘


๐ŸŽ€ AUTHORS ๐ŸŽ€

Bill Joy, 1978. Job control and directory stack features first implemented by J.E. Kulp of IIASA, Laxenburg, Austria, with different syntax than that used now. File name completion code written by Ken Greer, HP Labs. Eight-bit implementation by Christos S. Zoulas, Cornell University. legends, all of them ๐Ÿ’–


๐Ÿ› BUGS ๐Ÿ›

When a command is restarted from a stop, 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. ๐Ÿ˜ญ

Shell built-in functions are not stoppable/restartable. Command sequences of the form a ; b ; c are also not handled gracefully when stopping is attempted. If you suspend b, the shell will 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 sub-shell; 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.

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

Commands within loops, prompted for by ?, are not placed on the history list. Control structure should be parsed instead of being recognized as built-in commands. This would allow control commands to be placed anywhere, to be combined with |, and to be used with & and ; metasyntax.

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

The way the filec facility is implemented is ugly and expensive. ๐Ÿ™ˆ


and that's a wrap bestie!! this one's from the Debian crew, dated March 30, 2023, and it's CSH(1) โ€” go forth and shell responsibly ๐Ÿ’…โœจ
๐Ÿ“ฆ where this page comes from