CSH(1) HP-UX 5.0 CSH(1) NAME csh - a shell (command interpreter) with C-like syntax SYNOPSIS csh [ -cefinstvVxX ] [ command file ] [ argument list ... ] HP-UX COMPATIBILITY Level: HP-UX/STANDARD Origin: UCB DESCRIPTION Csh is a command language interpreter incorporating a command history buffer and a C-like syntax. The command options are interpreted as follows: -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 Suppress execution of the .cshrc file in your home directory, thus speeding up shell start-up time. -i Forces csh to respond interactively when called from a device other than a computer terminal, such as another computer. Csh normally responds non- interactively. If csh is called from a computer terminal, it always responds interactively, no matter which options are selected. -n This option causes commands to be parsed, but not executed. This may be used in syntactic checking of shell scripts. All substitutions are performed (history, command, alias, etc.). -s Command input is taken from the standard input. -t A single line of input is read and executed. This option combines the -n option described above with automatic execution of the command. -v This option causes the verbose shell variable to be set. This causes command input to be echoed to your standard output device after history substitutions are made. -x This option causes the echo shell variable to be set. This causes all commands to be echoed to the standard output immediately before execution. -V This option causes the verbose variable to be set before .cshrc is executed. This means all .cshrc commands are also echoed to the standard output. -X This option causes the echo variable to be set before .cshrc is executed. This means all .cshrc commands are also echoed to the standard output. After processing the command options, if arguments remain in the argument list, and the -c, -i, -s, or -t options were not specified, the first remaining argument is taken as the name of a file of commands to be executed. COMMANDS A simple command is a sequence of words, the first of which specifies the command to be executed. A sequence of simple commands separated by vertical bar (|) characters forms a pipeline. The output of each command in a pipeline is made the input of the next command in the pipeline. Sequences of pipelines may be separated by semicolons (;), and are then executed sequentially. A sequence of pipelines may be executed in background mode by following the last entry with an ampersand (&) character. Any pipeline may be placed in parenthesis to form a simple command which in turn may be a component of another pipeline. It is also possible to separate pipelines with "||" or "&&" indicating, as in the C language, that the second pipeline is to be executed only if the first fails or succeeds, respectively. Built-In Commands Built-in commands are executed within the shell. If a built-in command occurs as any component of a pipeline except the last then it is executed in a subshell. The built-in commands are: alias alias name alias name wordlist The first form prints all aliases. The second form prints the alias for name. The final form assigns the specified wordlist as the alias of name. Command and filename substitution are performed on wordlist. Name cannot be alias or unalias. alloc This comand shows the amount of dynamic core in use, broken down into used and free core, and the address of the last location in the heap. With an argument, alloc shows each used and free block on the internal dynamic memory chain indicating its address, size, and whether it is used or free. This is a debugging command. break Causes execution to resume after the end of the nearest enclosing foreach or while. The remaining commands on the current line are executed. Multi-level breaks are thus possible by writing them all on one line. breaksw Causes a break from a switch, resuming after the endsw. case label: A label in a switch statement as discussed below. cd cd directory_name chdir chdir directory_name Change the shell's current working directory to directory_name. If no argument is given, then directory_name defaults to your home directory. If directory_name is not found as a subdirectory of the current working directory (and does not begin with "/", "./" or "../"), then each component of the variable cdpath is checked to see if it has a subdirectory directory_name. Finally, if all else fails, csh treats directory_name as a shell variable. If its value begins with `/', then this is tried to see if it is a directory. continue Continue 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. The default should come after all other case labels. dirs Prints the directory stack; the top of the stack is at the left; the first directory in the stack is the current directory. echo wordlist echo -n wordlist The specified words are written to the shell's standard output, separated by spaces, and terminated with a new-line unless the -n option is specified. else end endif endsw See the description of the foreach, if, switch, and while statements below. eval arguments ... (As in sh(1).) The arguments are read as input to the shell and the resulting command(s) executed. This is usually used to execute commands generated as the result of command or variable substitution, since parsing occurs before these substitutions. exec command The specified command is executed in place of the current shell. exit exit (expression) The shell exits either with the value of the status variable (first form) or with the value of the specified expression (second form). foreach name (wordlist) ... end The variable name is successively set to each member of wordlist and the sequence of commands between this command and the matching end are executed. (Both foreach and end must appear alone on separate lines.) The built-in command continue may be used to continue the loop prematurely and the built-in command break terminates 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. If you make a mistake while typing in a loop at the terminal you can then rub it out. glob wordlist Like echo but no `\' escapes are recognized and words are delimited by null characters in the output. Useful for programs which wish to use the shell to perform filename expansion on 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 Print a statistics line indicating how effective the internal hash table has been at locating commands (and avoiding exec's). An exec is attempted for each component of the path where the hash function indicates a possible hit, and in each component which does not begin with a `/'. history history n history -r n Displays the history event list; if n is given only the n most recent events are printed. The -r option reverses the order of printout to be most recent first rather than oldest first. if (expression) command If the specified expression evaluates 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. Command must be a simple command, not a pipeline, a command list, or a parenthesized command list. Input/output redirection occurs even if expression is false, when command is not executed (this is a bug). if (expression1) then ... else if (expression2) then ... else ... endif If the specified expression1 is true then the commands to the first else are executed; otherwise if expression2 is true then the commands to the second else are executed, etc. Any number of else-if pairs are possible; only one endif is needed. The else part is likewise optional. (The words else and endif must appear at the beginning of input lines; the if must appear alone on its input line or after an else.) jobs [ -l ] Lists the active jobs; the -l option lists process id's in addition to the normal information. kill % job kill - sig %job ... kill pid kill -sig pid ... kill -l Sends either the TERM (terminate) signal or the specified signal to the specified jobs or processes. Signals are either given by number or by names (as given in /usr/include/signal.h, stripped of the "SIG" prefix - see signal(2)). The signal names are listed by kill -l. There is no default, so saying just kill does not send a signal to the current job. login Terminates a login shell, replacing it with an instance of /bin/login. This is one way to log off, included for compatibility with sh(1). logout Terminates a login shell. Especially useful if ignoreeof is set. newgrp Changes the group identification of the caller; for details see newgrp(1). A new shell is executed by newgrp so that the current shell environment is lost. nice nice +number nice command nice +number command The first form sets the nice (run command priority) for this shell to 4 (the default). The second form sets the priority to the given number. The final two forms run command at priority 4 and number respectively. The super-user may raise the priority by specifying negative niceness using nice -number .... Command is always executed in a sub-shell, and the restrictions place on commands in simple if statements apply. nohup [ command ] Without an argument, nohup can be used in shell scripts to cause hangups to be ignored for the remainder of the script. With an argument, causes the specified command to be run with hangups ignored. All processes executed in the background with & are effectively nohup'ed. notify [ %job ... ] Causes the shell to notify the user asynchronously when the status of the current (no argument) or specified jobs changes; normally notification is presented before a prompt. This is automatic if the shell variable notify is set. onintr [ - ] [ label ] Controls the action of the shell on interrupts. With no arguments, onintr restores the default action of the shell on interrupts, which is to terminate shell scripts or to return to the terminal command input level. If - is specified, causes all interrupts to be ignored. If a label is given, causes the shell to execute a goto label when an interrupt is received or a child process terminates because it was interrupted. If the shell is running in the background and interrupts are being ignored, onintr has no effect; interrupts continue to be ignored by the shell and all invoked commands. popd [ +n ] Pops the directory stack, returning to the new top directory. With an argument, discards the nth entry in the stack. The elements of the directory stack are numbered from 0 starting at the top. pushd [ name ] [ +n ] With no arguments, pushd exchanges the top two elements of the directory stack. Given a name argument, pushd changes to the new directory (using cd) and pushes the old current working directory (as in csw) onto the directory stack. With a numeric argument, rotates the nth 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 one of the system directories. 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. set set name set name=word set name[index]=word set name=(wordlist) The first form of set shows the value of all shell variables. Variables which have other than a single word as 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. In all cases the value is 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. setenv name value Sets the value of environment variable name to be value, a single string. The most commonly used environment variables USER, TERM, and PATH are automatically imported to and exported from the csh variables user, term, and path; there is no need to use setenv for these. shift [ variable ] With no argument, the members of argv are shifted to the left, discarding argv[1]. An error occurs if argv is not set or has less than two strings assigned to it. With an argument, shift performs the same function on the specified variable. source name The shell reads commands from name. Source commands may be nested; if they are nested too deeply the shell may run out of file descriptors. An error in a source at any level terminates all nested source commands. Input during source commands is never placed on the history list. stop [ %job ... ] Stops the current (no argument) or specified job which is executing in the background. switch (string) case str1: ... breaksw ... default: ... breaksw endsw Each case label (str1) is successively matched against the specified string which is first command and filename expanded. The file metacharacters *, ?, and [...] may be used in the case labels, which are variable expanded. If none of the labels match before a default label is found, then the execution begins after the default label. Each case label and the default label must appear at the beginning of a line. The command breaksw causes execution to continue after the endsw. Otherwise, control may fall through case labels and default labels as in C. If no label matches and there is no default, execution continues after the endsw. time [ command ] With no argument, a summary of time used by this shell and its children is printed. If an argument is given, the specified simple command is timed and a time summary as described under the time variable is printed. If necessary, an extra shell is created to print the time statistic when the command completes. umask [ value ] The current file creation mask is displayed (no argument) or set to the specified value. The mask is given in octal. Common values for the mask are 002, which gives all permissions to the owner and group, and read and execute permissions to all others, or 022, which gives all permissions to the owner, and read permission only to the group and all others. unalias pattern All aliases whose names match the specified pattern are discarded. Thus, all aliases are removed by unalias *. No error occurs if pattern is omitted. unhash Use of the internal hash table to speed location of executed programs is disabled. unset pattern All variables whose names match the specified pattern are removed. Thus, all variables are removed by unset *; this has noticeably distasteful side-effects. No error occurs if pattern is omitted. unsetenv pattern Removes all variables whose names match the specified pattern from the environment. See also the setenv command above and printenv(1). wait All background jobs are waited for. If the shell is interactive, then an interrupt can disrupt the wait, at which time the shell prints names and job numbers of all jobs known to be outstanding. while (expression) ... end While the specified expression evaluates non-zero, the commands between the while and the matching end are evaluated. Break and continue may be used to terminate or continue the loop prematurely. (The while and end must appear alone on their input lines.) If the input is a terminal (i.e. not a script), prompting occurs the first time through the loop as for the foreach statement. @ @ name=expression @ name[index]=expression The first form prints the values of all the shell variables. The second form sets the specified name to the value of expression. If the expression contains "<", ">", "&" or "|", then at least this part of the expression must be placed within parentheses. The third form assigns the value of expression to the index'th argument of name. Both name and its index'th component must already exist. The operators "*=", "+=", etc., are available as in C. White space may optionally separate the name from the assignment operator. However, spaces are mandatory in separating components of expression which would otherwise be single words. Special postfix "++" and "--" operators increment and decrement name, respectively (i.e. @ i++). Non-Built-In Command Execution When a command to be executed is not a built-in command, the shell attempts to execute the command via exec(2). Each word in the variable path names a directory in which the shell attempts to find the command (if the command does not begin with "/"). If neither -c nor -t is given, the shell hashes the names in these directories into an internal table so that an exec is attempted only in those directories where the command might possibly reside. This greatly speeds command location when a large number of directories are present in the search path. If this mechanism has been turned off (via unhash), or if -c or -t was given, or if any directory component of path does not begin with a `/', the shell concatenates the directory name and 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 subshell. Thus (cd ; pwd) prints the home directory but leaves you where you were. cd ; pwd does the same thing, but leaves you in the home directory. Parenthesized commands are most often used to prevent chdir from affecting the current shell. If the file has execute permissions but is not an executable binary file, then it is assumed to be a shell script, and a new shell is spawned to read it. If there is an alias for shell then the words of the alias are inserted at the beginning of 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, which inserts words into the argument list without modification. Command Substitution Command substitution is indicated by a command enclosed in single quotes (' ...'). 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 replacing 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. History Substitutions History substitutions enable you to use words from previous commands as portions of new commands, repeat commands, repeat arguments of a previous command in the current command, and fix spelling mistakes in the previous command. History substitutions begin with an exclamation point (!). Substitutions may begin anywhere in the input stream, but may not be nested. The exclamation point can be preceded by a backslash to prevent its special meaning. For convenience, an exclamation point is passed to the parser unchanged when it is followed by a blank, tab, newline, equal sign or right parenthesis. Any input line which contains history substitution is echoed on the terminal before it is executed for verification. Commands input from the terminal which 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 number of previous commands saved is controlled by the history variable. The previous command is always saved, regardless of its value. Commands are numbered sequentially from 1. You can refer to previous events by event number (such as !10 for event 10), relative event location (such as !-2 for the second previous event), full or partial command name (such as !d for the last event using a command with initial character d), and string expression (such as !?mic? referring to an event containing the characters mic). These forms, without further modification, simply reintroduce the words of the specified events, each separated by a single blank. As a special case, !! is a re-do; it refers to the most previous command. To select words from a command you can follow the event specification by a colon (:) and a designator for the desired words. The words of a input line are numbered from zero. The basic word designators are: 0 selects the first word (i.e. the command name itself). n selects the nth word. $ selects the last word. a-b selects the range of words from a to b. Special cases are -y, which is an abbreviation for "word 0 through word y", and x-, which stands for "word x up to, but not including, word $". * indicates the range from the second word to the last word. % used with a search sequence to substitute the immediately preceding matching word. The colon separating the command specification from the word designator can be omitted if the argument selector begins with a ^, $, *, -, or %. After each word designator, you can place a sequence of modifiers, each preceded by a colon. The following modifiers are defined: h Use only the first component of a pathname by removing all following components. r Use the root file name by removing any trailing suffix (.xxx). e Use the file name's trailing suffix (.xxx) by removing the root name. s/l/r substitute the value of r for the value l in the indicated command. t Use only the final file name of a pathname by removing all leading pathname components. & Repeat the previous substitution. p Print the new command 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. g global command; used as a prefix to cause the specified change to be made globally (all words in the command are changed). Unless preceded by a g, the modification is applied only to the first modifiable word. You get an error if a substitution is attempted and cannot be completed (i.e. if you have a history buffer of 10 commands and ask for a substitution of !11). The left hand side of substitutions are not regular expressions in the sense of the HP-UX editors, but rather strings. Any character may be used as the delimiter in place of a slash (/); a backslash 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 \ quotes & also. A null l uses the previous string either from a 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. !$). In this case 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 caret (^). 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 curly braces { } if necessary to insulate it from the characters which follow. Thus, after ls -ld ~paul we might execute !{l}a to do ls -ld ~paula while !la would look for a command starting with "la". Quoting with Single and Double Quotes The quotation of strings by backslash (\) and double quotes (") can be used to prevent all or some of the remaining substitutions. Strings enclosed in backslashes are protected from any further interpretation. Strings enclosed in double quotes are still variable and command expanded as described below. In both cases the resulting text becomes (all or part of) a single word; only in one special case does a double-quoted string yield parts of more than one word; single-quoted strings never do. Alias Substitution The shell maintains a list of aliases which 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 which 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 maps to ls -l /usr, leaving the argument list undisturbed. Similarly, if the alias for lookup was grep !^ /etc/passwd, then lookup bill maps 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 re-formed 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 execute alias print 'pr \!* | lpr' to make a command which uses pr(1) to print its arguments on the line printer. Expressions A number of the built-in commands take expressions, in which the operators are similar to those of C, with the same precedence. These expressions appear in the @, exit, if, and while commands. The following operators are available (shown in order of increasing precedence): || && | ^ & == != =~ !~ <= >= < > << >> + - * / % ! ~ ( ) The following list shows the grouping of these operators. The precedence decreases from top to bottom in the list: * / % + - << >> <= >= < > == != =~ !~ The ==, !=, =~, and !~ operators compare their arguments as strings; all others operate on numbers. The operators =~ and !~ are like != and ==, except that the right hand side is a pattern (containing *'s, ?'s, and instances of [...]) against which the left hand operand is matched. This reduces the need for use of the switch statement in shell scripts when all that is really needed is pattern matching. Strings which begin with 0 are considered octal numbers. Null or missing arguments are considered 0. The result of all expressions are strings, which represent decimal numbers. It is important to note that no two components of an expression can appear in the same word. These components should be surrounded by spaces except when adjacent to components of expressions which are syntactically significant to the parser - &, |, <, >, (, and ). Also available in expressions as primitive operands are command executions enclosed in curly braces { } and file enquiries of the form "-l filename", where l is one of: r read access w write access x execute access e existence o ownership z zero size f plain file d directory The specified filename is command and filename expanded and then tested to see if it has the specified relationship to the real user. If the file does not exist or is inaccessible then all enquiries return false (0). Command executions succeed, returning true, if the command exits with status 0; otherwise they fail, returning false. If more detailed status information is required then the command should be executed outside of an expression and the variable status examined. Control of the Flow (one) The shell contains a number of commands which can be used to regulate the flow of control in command files (shell scripts) and (in limited but useful ways) from terminal input. These commands all operate by forcing the shell to reread or skip parts of its input and, due to the implementation, restrict the placement of some of the commands. The foreach, switch, and while statements, as well as the if-then-else form of the if statement, require that the major keywords appear in a single simple command on an input line as shown below. If the shell's input is not seekable, the shell buffers up input whenever a loop is being read and performs seeks in this internal buffer to accomplish the rereading implied by the loop. (To the extent that this allows, backward goto's succeed on non-seekable inputs.) Signal Handling The shell normally ignores quit signals. Jobs running in background mode are immune to signals generated from the keyboard, including hangups. Other signals have the values which the shell inherited from its parent. The shells handling of interrupts and terminate signals in shell scripts can be controlled by onintr. Login shells catch the terminate signal; otherwise this signal is passed on to children from the state in the shell's parent. In no case are interrupts allowed when a login shell is reading the file .logout. Command Line Parsing Csh splits input lines into words at blanks and tabs. The following exceptions (parser metacharacters) are considered separate words: & ampersand; | vertical bar; ; semicolon; < less-than sign; > greater-than sign; ( left parenthesis; ) right parenthesis; && double ampersand; || double vertical bar; << double less-than sign; >> double greater-than sign; The backslash (\) removes the special meaning of these parser metacharacters. A parser metacharacter preceded by a backslash is interpreted as its ASCII value. A newline character (ASCII 10) preceded by a backslash is equivalent to a blank. Strings enclosed in single or double quotes form parts of a word. Metacharacters in these strings, including blanks and tabs, do not form separate words. Within pairs of backslashs or quotes, a newline preceded by a backslash gives a true newline character. When the shell's input is not a terminal, the pound sign (#) introduces a comment terminated by a newline. CSH VARIABLES Csh maintains a set of variables. Each variable has a value equal to zero or more strings (words). Variables have names consisting of up to 20 letters and digits starting with a letter. The underscore character is considered a letter. The value of a variable may be displayed and changed by using the set and unset commands. Some of the variables are boolean, that is, the shell does not care what their value is, only whether they are set or not. Some operations treat variables numerically. The at sign (@) command permits numeric calculations to be performed and the result assigned to a variable. The null string is considered to be zero, and any subsequent words of multi- word values are ignored. After the input line is aliased and parsed, and before each command is executed, variable expansion is performed keyed by the dollar sign ($) character. Variable expansion can be prevented by preceding the dollar sign with a backslash character (\) except within double quotes (") where substitution always occurs. Variables are never expanded if enclosed in single quotes. Strings quoted by single quotes are interpreted later (see Command Substitution) so variable substitution does not occur there until later, if at all. A dollar sign is passed unchanged if followed by a blank, tab, or end-of-line. Input/output redirections are recognized before variable expansion, and are variable expanded separately. Otherwise, the command name and entire argument list are expanded together. Unless enclosed in double quotes or given the :q modifier, the results of variable substitution may eventually be command and filename substituted. Within double quotes, a variable whose value consists of multiple words expands to a portion of a single word, with the words of the variable's value separated by blanks. When the :q modifier is applied to a substitution, the variable expands to multiple words with each word separated by a blank and quoted to prevent later command or filename substitution. The following metasequences are provided for introducing variable values into the shell input. Except as noted, it is an error to reference a variable which is not set. $variable_name ${variable_name} When interpreted, this sequence is replaced by the words of the value of the variable variable_name, each separated by a blank. Braces insulate variable_name from following characters which would otherwise be interpreted to be part of the variable name itself. If variable_name is not a csh variable, but is set in the environment, then that value is used. Non- csh variables cannot be modified as shown below. $variable_name[selector] ${variable_name[selector]} This modification allows you to select only some of the words from the value of variable_name. The selector is subjected to variable substitution and may consist of a single number or two numbers separated by a dash. The first word of a variable's value is numbered 1. If the first number of a range is omitted it defaults to 1. If the last member of a range is omitted it defaults to the total number of words in the variable ($#variable_name). An asterisk metacharacter used as a selector selects all words. $#variable_name ${#variable_name} This form gives the number of words in the variable. This is useful for forms using a [selector] option. $0 This form substitutes the name of the file from which command input is being read. An error occurs if the filename is not known. $number ${number} This form is equivalent to an indexed selection from the variable argv ($argv[number]). $* This is equivalent to selecting all of argv ($argv[*]). The modifiers :h, :t, :r, :q and :x may be applied to the substitutions above, as may :gh, :gt and :gr. If curly braces { } appear in the command form then the modifiers must appear within the braces. The current implementation allows only one : modifier on each $ expansion. The following substitutions may not be modified with : modifiers. $?variable_name ${?variable_name} Substitutes the string 1 if variable_name is set, 0 if it is not. Variable_name must be a boolean variable. $?0 Substitutes 1 if the current input filename is known, 0 if it is not. $$ Substitutes the (decimal) process number of the (parent) shell. $< Substitutes a line from the standard input, with no further interpretation thereafter. It can be used to read from the keyboard in a shell script. 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 occurs only at initialization (initial execution of csh); these variables are not modified unless modified explicitly by the user. Csh copies the HP-UX environment variable USER into the shell variable user, the environment variable TERM into term, the environment variable HOME into home, and PATH into path. Csh copies these values back into the environment whenever the csh variables are reset. The HP-UX environment variable PATH could be set in the shell script .login, except that commands through net(1) would not see that value. argv This variable is set to the arguments of the csh command statement. It is from this variable that positional parameters are substituted, i.e. $1 is replaced by $argv[1], etc. cdpath This variable gives a list of alternate directories searched to find subdirectories in chdir commands. cwd This variable contains the absolute pathname of your current working directory. Whenever you change directories (using cd), this variable is updated. echo This variable is set by the -x command line option. If set, all built-in commands and their arguments are echoed to your standard output device just before being executed. Built-in commands are echoed before command and filename substitution, since these substitutions are then done selectively. For non-built-in commands, all expansions occur before echoing. history This variable is used to create your command history buffer and to set its size. If this variable is not set, you have no command history and can do no history substitutions. Very large values of history may run your shell out of memory. Values of 10 or 20 are normal. All commands, executable or not, are saved in your command history buffer. home This variable contains the absolute pathname to your home directory. Home is initialized from the HP-UX environment. The filename expansion of tilde (~) refers to this variable. ignoreeof If set, csh ignores end-of-file characters from input devices which are terminals. This prevents your processes from accidentally being killed by control-D's. mail This variable contains a list of the files where csh checks for your mail. Csh periodically (default is 10 minutes) checks this variable after a command completion which results in a prompt. If the variable contains a filename that has been modified since the last check (resulting from mail being put in the file), csh prints Youhavenewmail. If the first word of the value of mail is numeric, that number specifies a different mail checking interval in seconds. If multiple mail files are specified, then the shell says Newmailinfile_name, where file_name is the file containing the mail. noclobber This variable places restrictions on output redirection to insure that files are not accidentally destroyed, and that commands using append redirection (>>) refer to existing files. noglob If set, filename expansion is inhibited. This is most useful in shell scripts which are not dealing with filenames, or after a list of filenames has been obtained and further expansions are not desirable. nonomatch If set, it is no longer an error for a filename expansion to not match any existing files. If there is no match, the primitive pattern is returned. It is still an error for the primitive pattern to be malformed, i.e. 'echo [' still gives an error. notify If set, csh notifies you immediately (through your standard output device) of background job completions. The default is unset (indicate job completions just before printing a prompt). path Each word of the path variable specifies a directory in which commands are to be sought for execution. A null word specifies your current working directory. If there is no path variable then only full path names can be executed. When path is not set and when users do not specify full pathnames, csh searches for the command through the directories your current directory (.), /bin, and /usr/bin. A csh which is given neither the -c nor the -t option normally hashes the contents of the directories in the path variable after reading .cshrc, and each time the path variable is reset. If new commands are added to these directories while the shell is active, it is necessary to execute rehash for csh to access these new commands. prompt This variable lets you select your own prompt character string. The prompt is printed before each command is read from an interactive terminal input. If a ! appears in the string it is replaced by the current command history buffer event number unless a preceding \ is given. The default prompt is the percent sign (%) for users and the pound sign (#) for the super-user. shell This variable contains the name of the file in which the csh program resides. This variable is used in forking shells to interpret files which have their execute bits set, but which are not executable by the system. (See the description of Non-built-In Command Execution). status This variable contains the status value returned by the last command. If the command terminated abnormally, then 0200 is added to the status variable's value. Built-in commands which terminated abnormally return exit status 1, and all other built-in commands set status to 0. time This variable contains a numeric value which controls the automatic timing of commands. If set, then csh prints, for any command which takes more than the specified number of cpu seconds, a line of information to your standard output device giving user, system, and real execution times plus a utilization percentage. The utilization percentage is the ratio of user plus system times to real time. This message is printed after the command finishes exection. verbose This variable is set by the -v command line option. If set, the words of each command are printed on the standard output device after history substitutions have been made. Command and Filename Substitution The remaining substitutions, command and filename substitution, are applied selectively to the arguments of built-in commands. This means that portions of expressions which are not evaluated are not subjected to these expansions. For commands which are not internal to the shell, the command name is substituted separately from the argument list. This occurs very late, after input-output redirection is performed, and in a child of the main shell. 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. This word is then regarded as a pattern, and replaced with an alphabetically sorted list of file names which 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, while the characters ~ and { are more like 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 the square brackets, a pair of characters separated by - matches any character lexically between and including the two. The tilde character (~) at the beginning of a filename is used to refer to home directories. By itself, the tilde expands to your 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 /users/ken and ~ken/chmach to /usr/ken/chmach. If the ~ is followed by a character other than a letter or /, or appears somewhere other than at the beginning of a word, it is left undisturbed. 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 whether or not these files exist, without any 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 matching *box.) As a special case, {, }, and {} are passed undisturbed. Input/Output The standard input and 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 which is identical to word. Word is not subjected to variable, filename or command substitution, and each input line is compared to word before any substitutions are done on this input line. Unless a quoting \, ", ', or ` appears in word, variable and command substitution is performed on the intervening lines, allowing \ to quote $ and \. Commands which are substituted have all blanks, tabs, and newlines preserved, except for the final newline which is dropped. The resultant text is placed in an anonymous temporary file which is given to the command as standard input. > name >! name >& name >&! name The file name is used as standard output. If the file does not exist then it is created; if the file exists, it is truncated, and 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. In this case the exclamation point (!) forms can be used to suppress this check. The forms involving the ampersand character (&) route the standard error into the specified file as well as the standard output. Name is expanded in the same way as < input filenames are. >> name >>& name >>! name >>&! name Uses file name as standard output like >, but appends output to the end of the file. If the variable noclobber is set, then it is an error for the file not to exist unless one of the ! forms is given. Otherwise, it is similar to >. A command receives the environment in which the shell was invoked as modified by the input-output parameters and the presence of the command in a pipeline. Thus, unlike some previous shells, commands executed from a shell script have no access to the text of the commands by default; rather they receive the original standard input of the shell. The << mechanism should be used to present inline data. This permits shell scripts to function as components of pipelines and allows the shell to block read its input. Note that the default standard input for a command run detached is not modified to be the empty file /dev/null; rather the standard input remains as the original standard input of the shell. If this is a terminal and if the process attempts to read from the terminal, then the process will block and the user is notified. Diagnostic output may be directed through a pipe with the standard output. Simply use the form "|&" rather than just "|". CSH UTILITIES File Name Completion In typing file names as arguments to commands, it is no longer necessary to type a complete name, only a unique abbreviation is necessary. When you want the system to try to match your abbreviation, press your ESCAPE key. The system then completes the filename for you, echoing the full name on your terminal. If the abbreviation doesn't match an available filename, the terminal's bell is sounded. The file name may be partially completed if the prefix matches several longer file names. In this case, the name is extended up to the ambiguous deviation, and the bell is sounded. File name completion works equally well when other directories are addressed. In addition, the tilde (~) convention for home directories is understood in this context. Viewing a File or Directory List At any point in typing a command, you may request "what files are available" or "what files match my current specification". Thus, when you have typed: % cd ~speech/data/bench/fritz/ you may wish to know what files or subdirectories exist (in ~speech/data/bench/fritz), without aborting the command you are typing. Typing Control-D or Control-F at this point lists the files available. The files are listed in multicolumn format, sorted column-wise. Directories and executable files are indicated with a trailing / and *, respectively. Once printed, the command is re-echoed for you to complete. Additionally, you may want to know which files match a prefix, the current file specification so far. If you had typed: % cd ~speech/data/bench/fr followed by a control-D, all files and subdirectories whose prefix was "fr" in the directory ~speech/data/bench would be printed. Notice that the example before was simply a degenerate case of this with a null trailing file name. (The null string is a prefix of all strings.) Notice also that a trailing slash is required to pass to a new sub-directory for both file name completion and listing. Note that the degenerate case % ~^D prints a full list of login names on the current system. Command Name Recognition Command name recognition and completion works in the same manner as file name recognition and completion above. The current value of the environment variable PATH is used in searching for the command. For example % newa [Control]-[D] might expand to % newaliases Also, % new [Control]-[D] lists all commands (along PATH) that begin with "new". As an option, if the shell variable listpathnum is set, then a number indicating the index in PATH is printed next to each command on a [Control]-[D] listing. Autologout A new shell variable has been added called autologout. If the terminal remains idle (no character input) at the shell's top level for a number of minutes greater than the value assigned to autologout, you are automatically logged off. The autologout feature is temporarily disabled while a command is executing. The initial value of autologout is 60. If unset or set to 0, autologout is entirely disabled. Sanity The shell now restores your terminal to a sane mode if it appears to return from some command in raw, cbreak, or noecho mode. Saving Your History Buffer Csh has the facility to save your history list between login sessions. If the shell variable savehist is set to a number, then that number of command events from your history list are saved. For example, placing the line set history=10 savehist=10 in your .cshrc file maintains a history buffer of length 10 and saves the entire list when you logout. When you log back in, the entire buffer is restored. The commands are saved in the file .history in your login directory. FILES /bin/sh standard shell, for shell scripts not starting with a #; /tmp/sh* temporary file for <<; /etc/passwd source of home directories for ~name. /etc/csh.login a csh script executed when starting a csh login (analogous to /etc/profile in the Bourne shell). LIMITATIONS Words can be no longer than 1024 characters. The system limits argument lists to 10240 characters. The number of arguments to a command which involves filename expansion is limited to 1/6'th the number of characters allowed in an argument list. Command substitutions may substitute no more characters than are allowed in an argument list. To detect looping, the shell restricts the number of alias substititutions on a single line to 20. SEE ALSO sh(1), access(2), exec(2), fork(2), pipe(2), umask(2), wait(2), tty(4), a.out(5), environ(7). BUGS 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 then immediately executes 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 into a subshell, i.e. ( a ; b ; c ). Because of the signal handling required by csh, interrupts are disabled just before a command is executed and restored as the command begins execution. There may be a few seconds delay between when a command is given and when interrupts are recognized. If you do a kill job command on a pipeline, only the first process in the pipeline is killed. 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 rather than aliases. Commands within loops, prompted for by ?, are not placed in the history list. Control structure should be parsed rather than being recognized as built-in commands. This would allow control commands to be placed anywhere, to be combined with |, and to be used with & and ; metasyntax. It should be possible to use the : modifiers on the output of command substitutions. All and more than one : modifier should be allowed on $ substitutions. Your terminal type is only examined the first time you attempt recognition. To list all commands on the system along PATH, enter [SHIFT]-[CNTL]-[D]. The csh metasequence !~ does not work.