CSH(1)
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 inargv. ๐ฅ-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 variableHOMEis 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-lis the only flag specified). ๐-mโ Read.cshrc, regardless of its owner and group. This option is dangerous and should only be used bysu(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), sinceexitwill 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 theverbosevariable to be set even before.cshrcis executed. ๐ฃ๏ธ-vโ Causes theverbosevariable to be set, with the effect that command input is echoed after history substitution. ๐-Xโ Causes theechovariable to be set even before.cshrcis executed. ๐ข-xโ Causes theechovariable 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) wordnโ n'th argument^โ first argument; i.e.,1$โ last argument%โ word matched by (immediately preceding)?s?searchx-yโ range of words-yโ abbreviates0-y*โ abbreviates^-$, or nothing if only 1 word in eventx*โ abbreviatesx-$x-โ likex*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.xxxcomponent, leaving the root name.eโ Remove all but the extension.xxxpart.s/l/r/โ Substitutelforr.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 withgto apply a substitution globally.pโ Print the new command line but do not execute it.qโ Quote the substituted words, preventing further substitutions.xโ Likeq, 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; seemktemp(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โ Usesnameas the standard output, like>but it drops the output at the end of the file instead of wiping it. If the variablenoclobberis 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, sonoclobbercan't ruin your day.>>&! nameโ both at once: append, stderr included,noclobberoverridden.
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 accesswโ write accessxโ execute accesseโ existenceoโ ownershipzโ zero sizefโ plain filedโ directorypโ 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. ๐
aliasalias namealias name wordlistโ The first form prints every alias. The second prints the alias forname. The final form assigns the givenwordlistas the alias ofname;wordlistgets command and filename substituted. Oh, andnameis not allowed to bealiasorunalias. Sorry babe, those are taken. ๐bgbg %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 enclosingforeachorwhile. 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 aswitch, resuming after theendsw.case label:โ A label in aswitchstatement, as discussed below.cdcd namechdirchdir nameโ Changes the shell's working directory to directoryname. No argument? You go to the user's home directory. Ifnameisn't found as a subdirectory of the current directory (and doesn't begin with/,./or../), then each component of the variablecdpathgets checked to see if it has a subdirectoryname. And finally, if all else fails butnameis 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 enclosingwhileorforeach. The rest of the commands on the current line are executed.default:โ Labels the default case in aswitchstatement. It should come after all thecaselabels. 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 wordlistecho -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. โจelseendendifendswโ See the descriptions of theforeach,if,switch, andwhilestatements below.eval arg ...โ (Same as insh(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. Seetset(1)for an example of usingeval. ๐งexec commandโ The specified command is executed in place of the current shell. No going back.exitexit (expr)โ The shell exits with the value of thestatusvariable (first form) or with the value of the specifiedexpr(second form). Bye bestie ๐fgfg %job ...โ Brings the current or specified jobs into the foreground, continuing them if they were stopped.foreach name (wordlist)...endโ The variablenamegets successively set to each member ofwordlist, and the sequence of commands between this command and the matchingendgets executed. (Bothforeachandendmust appear alone on separate lines โ no sneaking extra stuff on those lines.) The built-incontinuecan continue the loop prematurely, and the built-inbreakcan 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โ Likeecho, 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 specifiedwordis filename and command expanded to yield a string of the formlabel. 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 avoidingexec's). Anexecis 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:commandmust be a simple command โ not a pipeline, a command list, or a parenthesized command list. and input/output redirection occurs even ifexpris false, i.e., whencommandis 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 wordselseandendifmust appear at the beginning of input lines; theifmust appear alone on its input line or after anelse.)
โจ 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 themlock(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/setenvname /setenvname 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,TERMandPATHโ get auto-imported and auto-exported to the csh variablesuser,termandpath. so you genuinely do not needsetenvfor those. they're already handled ๐
- first form: dumps every single environment variable you've got rn. literally the same thing as
shift/shiftvariable- shuffles the members of
argvto the left and just dropsargv[1]into the void ๐ณ๏ธ - it's an error if
argvisn't set, or if its value has fewer than one word. - second form does the exact same glow-up to whichever variable you name.
- shuffles the members of
sourcename /source -hname- shell reads commands straight out of name. very "run this script, bestie."
sourcecommands can be nested โ but if you nest them too deep, the shell may legitimately run out of file descriptors ๐ญ- an error in a
sourceat any level terminates all nestedsourcecommands. it's giving domino effect. - normally, input during
sourcecommands does not get put on the history list. the-hoption 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 bysu(1). iconic little freeze-frame.
- makes the shell stop in its tracks, exactly like it got sent a stop signal with
switch(string) โ withcase,default,breaksw,endsw:- every
caselabel 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
defaultlabel shows up, execution starts after thedefaultlabel. - every
caselabel and thedefaultlabel must appear at the beginning of a line. non-negotiable. breakswmakes execution continue after theendsw. 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 theendsw. keep it moving ๐ถโโ๏ธ
- every
switch (string)
case str1:
...
breaksw
...
default:
...
breaksw
endsw
time/timecommand- 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
timevariable gets printed. - if it's necessary, an extra shell is created just to print that time statistic when the command completes.
umask/umaskvalue- first form displays the file creation mask, second form sets it to value.
- the mask is given in octal. common values:
002gives all access to the group plus read and execute access to others, or022gives 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.
unaliaspattern- 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.
- throws away all aliases whose names match pattern. so
unhash- disables use of the internal hash table that speeds up finding executed programs. so long, shortcut โ๏ธ
unlimit/unlimitresource /unlimit -h/unlimit -hresource- removes the limitation on resource.
- no resource specified? all resource limitations get removed.
-hgiven? the corresponding hard limits get removed.- only the superuser may do this. ๐
unsetpattern- 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.
- removes all variables whose names match pattern. so
unsetenvpattern- removes all variables whose names match pattern from the environment.
- see also
setenvabove andprintenv(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.
whichcommand- 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
whileand the matchingendget evaluated. breakandcontinuecan terminate or continue the loop early.- the
whileand theendmust appear alone on their input lines. - prompting happens here the first time through the loop, same as for the
foreachstatement, if the input is a terminal.
- while the given expression evaluates to non-zero, the commands between the
%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 inchdircommands.cwdโ the full pathname of the current directory.echoโ set when the-xcommand-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 ofhistorymay 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
mailis 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.
- if the first word of the value of
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 โ soecho [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 nopathvariable at all? Then only full path names will execute, periodt. The usual search path is.,/bin,/usr/bin,/sbinand/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-cnor the-toption will normally hash the contents of the directories in thepathvariable after reading.cshrc, and again each time thepathvariable is reset. If new commands get added to those directories while the shell is still active, it may be necessary to do arehashor 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~/.historywhen the user logs out. Any command that has been referenced in this many events will be saved. During start up the shell sources~/.historyinto the history list, which is the whole reason history can be saved across logins ๐ซถ. Warning though: too large values ofsavehistwill slow down the shell during start up. And ifsavehistis just set (no number, just vibes), the shell will use the value ofhistory.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, then0200is added to the status. Built-in commands that fail return exit status1, all other built-in commands set status to0. ๐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-vcommand-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.cshrcat 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
- debian trixie: csh 20240808-2 ยท BSD-3-Clause
- ubuntu noble: csh 20230828-1 ยท BSD-3-Clause
- ubuntu questing: csh 20240808-3
- ubuntu resolute: csh 20240808-4 ยท BSD-3-Clause
- ubuntu stonking: csh 20240808-4 ยท BSD-3-Clause
- Copyright (c) 1980, 1990, 1993 The Regents of the University of California. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms