xref: /netbsd-src/bin/csh/csh.1 (revision 1394f01b4a9e99092957ca5d824d67219565d9b5)
1.\"	$NetBSD: csh.1,v 1.14 1997/06/23 20:33:31 pk Exp $
2.\"
3.\" Copyright (c) 1980, 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	@(#)csh.1	8.2 (Berkeley) 1/21/94
35.\"
36.Dd January 21, 1994
37.Dt CSH 1
38.Os BSD 4
39.Sh NAME
40.Nm csh
41.Nd a shell (command interpreter) with C-like syntax
42.Sh SYNOPSIS
43.Nm csh
44.Op Fl bcefinstvVxX
45.Op arg ...
46.Nm csh
47.Op Fl l
48.Sh DESCRIPTION
49The
50.Nm csh
51is a command language interpreter
52incorporating a history mechanism (see
53.Nm History Substitutions ) ,
54job control facilities (see
55.Nm Jobs ) ,
56interactive file name
57and user name completion (see
58.Nm File Name Completion ) ,
59and a C-like syntax. It is used both as an interactive
60login shell and a shell script command processor.
61.Ss Argument list processing
62If the first argument (argument 0) to the shell is
63.Ql Fl \& ,
64then this is a login shell.
65A login shell also can be specified by invoking the shell with the
66.Ql Fl l
67flag as the only argument.
68.Pp
69The rest of the flag arguments are interpreted as follows:
70.Bl -tag -width 5n
71.It Fl b
72This flag forces a ``break'' from option processing, causing any further
73shell arguments to be treated as non-option arguments.
74The remaining arguments will not be interpreted as shell options.
75This may be used to pass options to a shell script without confusion
76or possible subterfuge.
77The shell will not run a set-user ID script without this option.
78.It Fl c
79Commands are read from the (single) following argument which must
80be present.
81Any remaining arguments are placed in
82.Ar argv .
83.It Fl e
84The shell exits if any invoked command terminates abnormally
85or yields a non-zero exit status.
86.It Fl f
87The shell will start faster, because it will neither search for nor
88execute commands from the file
89.Pa \&.cshrc
90in the invoker's home directory.
91.It Fl i
92The shell is interactive and prompts for its top-level input,
93even if it appears not to be a terminal.
94Shells are interactive without this option if their inputs
95and outputs are terminals.
96.It Fl l
97The shell is a login shell (only applicable if
98.Fl l
99is the only flag specified).
100.It Fl n
101Commands are parsed, but not executed.
102This aids in syntactic checking of shell scripts.
103.It Fl s
104Command input is taken from the standard input.
105.It Fl t
106A single line of input is read and executed.
107A
108.Ql \e
109may be used to escape the newline at the end of this
110line and continue onto another line.
111.It Fl v
112Causes the
113.Ar verbose
114variable to be set, with the effect
115that command input is echoed after history substitution.
116.It Fl x
117Causes the
118.Ar echo
119variable to be set, so that commands are echoed immediately before execution.
120.It Fl V
121Causes the
122.Ar verbose
123variable to be set even before
124.Pa .cshrc
125is executed.
126.It Fl X
127Is to
128.Fl x
129as
130.Fl V
131is to
132.Fl v .
133.El
134.Pp
135After processing of flag arguments, if arguments remain but none of the
136.Fl c ,
137.Fl i ,
138.Fl s ,
139or
140.Fl t
141options were given, the first argument is taken as the name of a file of
142commands to be executed.
143The shell opens this file, and saves its name for possible resubstitution
144by `$0'.
145Since many systems use either the standard version 6 or version 7 shells
146whose shell scripts are not compatible with this shell, the shell will
147execute such a `standard' shell if the first character of a script
148is not a `#', i.e., if the script does not start with a comment.
149Remaining arguments initialize the variable
150.Ar argv .
151.Pp
152An instance of
153.Nm csh
154begins by executing commands from the file
155.Pa /etc/csh.cshrc
156and,
157if this is a login shell,
158.Pa \&/etc/csh.login .
159It then executes
160commands from
161.Pa \&.cshrc
162in the
163.Ar home
164directory of the invoker, and, if this is a login shell, the file
165.Pa \&.login
166in the same location.
167It is typical for users on crt's to put the command ``stty crt''
168in their
169.Pa \&.login
170file, and to also invoke
171.Xr tset  1
172there.
173.Pp
174In the normal case, the shell will begin reading commands from the
175terminal, prompting with `% '.
176Processing of arguments and the use of the shell to process files
177containing command scripts will be described later.
178.Pp
179The shell repeatedly performs the following actions:
180a line of command input is read and broken into
181.Ar words  .
182This sequence of words is placed on the command history list and parsed.
183Finally each command in the current line is executed.
184.Pp
185When a login shell terminates it executes commands from the files
186.Pa .logout
187in the user's
188.Ar home
189directory and
190.Pa /etc/csh.logout .
191.Ss Lexical structure
192The shell splits input lines into words at blanks and tabs with the
193following exceptions.
194The characters
195`&' `\&|' `;' `<' `>' `(' `)'
196form separate words.
197If doubled in `&&', `\&|\&|', `<<' or `>>' these pairs form single words.
198These parser metacharacters may be made part of other words, or prevented their
199special meaning, by preceding them with `\e'.
200A newline preceded by a `\e' is equivalent to a blank.
201.Pp
202Strings enclosed in matched pairs of quotations,
203`'\|', `\*(ga' or `"',
204form parts of a word; metacharacters in these strings, including blanks
205and tabs, do not form separate words.
206These quotations have semantics to be described later.
207Within pairs of `\'' or `"' characters, a newline preceded by a `\e' gives
208a true newline character.
209.Pp
210When the shell's input is not a terminal,
211the character `#' introduces a comment that continues to the end of the
212input line.
213It is prevented this special meaning when preceded by `\e'
214and in quotations using `\`', `\'', and `"'.
215.Ss Commands
216A simple command is a sequence of words, the first of which
217specifies the command to be executed.
218A simple command or
219a sequence of simple commands separated by `\&|' characters
220forms a pipeline.
221The output of each command in a pipeline is connected to the input of the next.
222Sequences of pipelines may be separated by `;', and are then executed
223sequentially.
224A sequence of pipelines may be executed without immediately
225waiting for it to terminate by following it with an `&'.
226.Pp
227Any of the above may be placed in `(' `)' to form a simple command (that
228may be a component of a pipeline, etc.).
229It is also possible to separate pipelines with `\&|\&|' or `&&' showing,
230as in the C language,
231that the second is to be executed only if the first fails or succeeds
232respectively. (See
233.Em Expressions . )
234.Ss Jobs
235The shell associates a
236.Ar job
237with each pipeline.  It keeps
238a table of current jobs, printed by the
239.Ar jobs
240command, and assigns them small integer numbers.  When
241a job is started asynchronously with `&', the shell prints a line that looks
242like:
243.Bd -filled -offset indent
244.Op 1
2451234
246.Ed
247.Pp
248showing that the job which was started asynchronously was job number
2491 and had one (top-level) process, whose process id was 1234.
250.Pp
251If you are running a job and wish to do something else you may hit the key
252.Nm ^Z
253(control-Z) which sends a STOP signal to the current job.
254The shell will then normally show that the job has been `Stopped',
255and print another prompt.  You can then manipulate the state of this job,
256putting it in the
257.Em background
258with the
259.Ar bg
260command, or run some other
261commands and eventually bring the job back into the foreground with
262the
263.Em foreground
264command
265.Ar fg  .
266A
267.Nm ^Z
268takes effect immediately and
269is like an interrupt in that pending output and unread input are discarded
270when it is typed.  There is another special key
271.Nm ^Y
272that does not generate a STOP signal until a program attempts to
273.Xr read  2
274it.
275This request can usefully be typed ahead when you have prepared some commands
276for a job that you wish to stop after it has read them.
277.Pp
278A job being run in the background will stop if it tries to read
279from the terminal.  Background jobs are normally allowed to produce output,
280but this can be disabled by giving the command ``stty tostop''.
281If you set this
282tty option, then background jobs will stop when they try to produce
283output like they do when they try to read input.
284.Pp
285There are several ways to refer to jobs in the shell.  The character
286`%' introduces a job name.  If you wish to refer to job number 1, you can
287name it as `%1'.  Just naming a job brings it to the foreground; thus
288`%1' is a synonym for `fg %1', bringing job number 1 back into the foreground.
289Similarly saying `%1 &' resumes job number 1 in the background.
290Jobs can also be named by prefixes of the string typed in to start them,
291if these prefixes are unambiguous, thus `%ex' would normally restart
292a suspended
293.Xr ex  1
294job, if there were only one suspended job whose name began with
295the string `ex'.  It is also possible to say `%?string'
296which specifies a job whose text contains
297.Ar string ,
298if there is only one such job.
299.Pp
300The shell maintains a notion of the current and previous jobs.
301In output about jobs, the current job is marked with a `+'
302and the previous job with a `\-'.  The abbreviation `%+' refers
303to the current job and `%\-' refers to the previous job.  For close
304analogy with the syntax of the
305.Ar history
306mechanism (described below),
307`%%' is also a synonym for the current job.
308.Pp
309The job control mechanism requires that the
310.Xr stty 1
311option
312.Ic new
313be set. It is an artifact from a
314.Em new
315implementation
316of the
317tty driver that allows generation of interrupt characters from
318the keyboard to tell jobs to stop.  See
319.Xr stty 1
320for details on setting options in the new tty driver.
321.Ss Status reporting
322This shell learns immediately whenever a process changes state.
323It normally informs you whenever a job becomes blocked so that
324no further progress is possible, but only just before it prints
325a prompt.  This is done so that it does not otherwise disturb your work.
326If, however, you set the shell variable
327.Ar notify ,
328the shell will notify you immediately of changes of status in background
329jobs.
330There is also a shell command
331.Ar notify
332that marks a single process so that its status changes will be immediately
333reported.  By default
334.Ar notify
335marks the current process;
336simply say `notify' after starting a background job to mark it.
337.Pp
338When you try to leave the shell while jobs are stopped, you will
339be warned that `You have stopped jobs.'  You may use the
340.Ar jobs
341command to see what they are.  If you do this or immediately try to
342exit again, the shell will not warn you a second time, and the suspended
343jobs will be terminated.
344.Ss File Name Completion
345When the file name completion feature is enabled by setting
346the shell variable
347.Ar filec
348(see
349.Ic set ) ,
350.Nm csh
351will
352interactively complete file names and user names from unique
353prefixes, when they are input from the terminal followed by
354the escape character (the escape key, or control-[)
355For example,
356if the current directory looks like
357.Bd -literal -offset indent
358DSC.OLD  bin      cmd      lib      xmpl.c
359DSC.NEW  chaosnet cmtest   mail     xmpl.o
360bench    class    dev      mbox     xmpl.out
361.Ed
362.Pp
363and the input is
364.Pp
365.Dl % vi ch<escape>
366.Pp
367.Nm csh
368will complete the prefix ``ch''
369to the only matching file name ``chaosnet'', changing the input
370line to
371.Pp
372.Dl % vi chaosnet
373.Pp
374However, given
375.Pp
376.Dl % vi D<escape>
377.Pp
378.Nm csh
379will only expand the input to
380.Pp
381.Dl % vi DSC.
382.Pp
383and will sound the terminal bell to indicate that the expansion is
384incomplete, since there are two file names matching the prefix ``D''.
385.Pp
386If a partial file name is followed by the end-of-file character
387(usually control-D), then, instead of completing the name,
388.Nm csh
389will list all file names matching the prefix.  For example,
390the input
391.Pp
392.Dl % vi D<control-D>
393.Pp
394causes all files beginning with ``D'' to be listed:
395.Pp
396.Dl DSC.NEW	DSC.OLD
397.Pp
398while the input line remains unchanged.
399.Pp
400The same system of escape and end-of-file can also be used to
401expand partial user names, if the word to be completed
402(or listed) begins with the character ``~''.  For example,
403typing
404.Pp
405.Dl cd ~ro<escape>
406.Pp
407may produce the expansion
408.Pp
409.Dl cd ~root
410.Pp
411The use of the terminal bell to signal errors or multiple matches
412can be inhibited by setting the variable
413.Ar nobeep  .
414.Pp
415Normally, all files in the particular directory are candidates
416for name completion.  Files with certain suffixes can be excluded
417from consideration by setting the variable
418.Ar fignore
419to the
420list of suffixes to be ignored.  Thus, if
421.Ar fignore
422is set by
423the command
424.Pp
425.Dl % set fignore = (.o .out)
426.Pp
427then typing
428.Pp
429.Dl % vi x<escape>
430.Pp
431would result in the completion to
432.Pp
433.Dl % vi xmpl.c
434.Pp
435ignoring the files "xmpl.o" and "xmpl.out".
436However, if the only completion possible requires not ignoring these
437suffixes, then they are not ignored.  In addition,
438.Ar fignore
439does not affect the listing of file names by control-D.  All files
440are listed regardless of their suffixes.
441.Ss Substitutions
442We now describe the various transformations the shell performs on the
443input in the order in which they occur.
444.Ss History substitutions
445History substitutions place words from previous command input as portions
446of new commands, making it easy to repeat commands, repeat arguments
447of a previous command in the current command, or fix spelling mistakes
448in the previous command with little typing and a high degree of confidence.
449History substitutions begin with the character `!' and may begin
450.Ar anywhere
451in the input stream (with the proviso that they
452.Nm "do not"
453nest.)
454This `!' may be preceded by a `\e' to prevent its special meaning; for
455convenience, an `!' is passed unchanged when it is followed by a blank,
456tab, newline, `=' or `('.
457(History substitutions also occur when an input line begins with `\*(ua'.
458This special abbreviation will be described later.)
459Any input line that contains history substitution is echoed on the terminal
460before it is executed as it could have been typed without history substitution.
461.Pp
462Commands input from the terminal that consist of one or more words
463are saved on the history list.
464The history substitutions reintroduce sequences of words from these
465saved commands into the input stream.
466The size of the history list is controlled by the
467.Ar history
468variable; the previous command is always retained,
469regardless of the value of the history variable.
470Commands are numbered sequentially from 1.
471.Pp
472For definiteness, consider the following output from the
473.Ar history
474command:
475.Bd -literal -offset indent
476\09  write michael
47710  ex write.c
47811  cat oldwrite.c
47912  diff *write.c
480.Ed
481.Pp
482The commands are shown with their event numbers.
483It is not usually necessary to use event numbers, but the current event
484number can be made part of the
485.Ar prompt
486by placing an `!' in the prompt string.
487.Pp
488With the current event 13 we can refer to previous events by event
489number `!11', relatively as in `!\-2' (referring to the same event),
490by a prefix of a command word
491as in `!d' for event 12 or `!wri' for event 9, or by a string contained in
492a word in the command as in `!?mic?' also referring to event 9.
493These forms, without further change, simply reintroduce the words
494of the specified events, each separated by a single blank.
495As a special case, `!!' refers to the previous command; thus `!!'
496alone is a
497.Ar redo .
498.Pp
499To select words from an event we can follow the event specification by
500a `:' and a designator for the desired words.
501The words of an input line are numbered from 0,
502the first (usually command) word being 0, the second word (first argument)
503being 1, etc.
504The basic word designators are:
505.Pp
506.Bl -tag -width Ds -compact -offset indent
507.It \&0
508first (command) word
509.It Ar n
510.Ar n Ns 'th
511argument
512.It \*(ua
513first argument,  i.e., `1'
514.It $
515last argument
516.It %
517word matched by (immediately preceding)
518.No \&? Ns Ar s Ns \&?
519search
520.It Ar \&x\-y
521range of words
522.It Ar \&\-y
523abbreviates
524.Ar `\&0\-y\'
525.It *
526abbreviates `\*(ua\-$', or nothing if only 1 word in event
527.It Ar x*
528abbreviates
529.Ar `x\-$\'
530.It Ar x\-
531like
532.Ar `x*\'
533but omitting word `$'
534.El
535.Pp
536The `:' separating the event specification from the word designator
537can be omitted if the argument selector begins with a `\*(ua', `$', `*'
538`\-' or `%'.
539After the optional word designator can be
540placed a sequence of modifiers, each preceded by a `:'.
541The following modifiers are defined:
542.Pp
543.Bl -tag -width Ds -compact -offset indent
544.It h
545Remove a trailing pathname component, leaving the head.
546.It r
547Remove a trailing `.xxx' component, leaving the root name.
548.It e
549Remove all but the extension `.xxx' part.
550.It s Ns Ar /l/r/
551Substitute
552.Ar l
553for
554.Ar r
555.It t
556Remove all leading pathname components, leaving the tail.
557.It \&&
558Repeat the previous substitution.
559.It g
560Apply the change once on each word, prefixing the above, e.g., `g&'.
561.It a
562Apply the change as many times as possible on a single word, prefixing
563the above. It can be used together with `g' to apply a substitution
564globally.
565.It p
566Print the new command line but do not execute it.
567.It q
568Quote the substituted words, preventing further substitutions.
569.It x
570Like q, but break into words at blanks, tabs and newlines.
571.El
572.Pp
573Unless preceded by a `g' the change is applied only to the first
574modifiable word.  With substitutions, it is an error for no word to be
575applicable.
576.Pp
577The left hand side of substitutions are not regular expressions in the sense
578of the editors, but instead strings.
579Any character may be used as the delimiter in place of `/';
580a `\e' quotes the delimiter into the
581.Ar l  " "
582and
583.Ar r  " "
584strings.
585The character `&' in the right hand side is replaced by the text from
586the left.
587A `\e' also quotes `&'.
588A null
589.Ar l
590(`//')
591uses the previous string either from an
592.Ar l
593or from a
594contextual scan string
595.Ar s
596in
597.No \&`!? Ns Ar s Ns \e?' .
598The trailing delimiter in the substitution may be omitted if a newline
599follows immediately as may the trailing `?' in a contextual scan.
600.Pp
601A history reference may be given without an event specification, e.g., `!$'.
602Here, the reference is to the previous command unless a previous
603history reference occurred on the same line in which case this form repeats
604the previous reference.
605Thus `!?foo?\*(ua !$' gives the first and last arguments
606from the command matching `?foo?'.
607.Pp
608A special abbreviation of a history reference occurs when the first
609non-blank character of an input line is a `\*(ua'.
610This is equivalent to `!:s\*(ua' providing a convenient shorthand for substitutions
611on the text of the previous line.
612Thus `\*(ualb\*(ualib' fixes the spelling of
613`lib'
614in the previous command.
615Finally, a history substitution may be surrounded with `{' and `}'
616if necessary to insulate it from the characters that follow.
617Thus, after `ls \-ld ~paul' we might do `!{l}a' to do `ls \-ld ~paula',
618while `!la' would look for a command starting with `la'.
619.Pp
620.Ss Quotations with \' and \&"
621The quotation of strings by `\'' and `"' can be used
622to prevent all or some of the remaining substitutions.
623Strings enclosed in `\'' are prevented any further interpretation.
624Strings enclosed in `"' may be expanded as described below.
625.Pp
626In both cases the resulting text becomes (all or part of) a single word;
627only in one special case (see
628.Em Command Substitution
629below) does a `"' quoted string yield parts of more than one word;
630`\'' quoted strings never do.
631.Ss Alias substitution
632The shell maintains a list of aliases that can be established, displayed
633and modified by the
634.Ar alias
635and
636.Ar unalias
637commands.
638After a command line is scanned, it is parsed into distinct commands and
639the first word of each command, left-to-right, is checked to see if it
640has an alias.
641If it does, then the text that is the alias for that command is reread
642with the history mechanism available
643as though that command were the previous input line.
644The resulting words replace the
645command and argument list.
646If no reference is made to the history list, then the argument list is
647left unchanged.
648.Pp
649Thus if the alias for `ls' is `ls \-l' the command `ls /usr' would map to
650`ls \-l /usr', the argument list here being undisturbed.
651Similarly if the alias for `lookup' was `grep !\*(ua /etc/passwd' then
652`lookup bill' would map to `grep bill /etc/passwd'.
653.Pp
654If an alias is found, the word transformation of the input text
655is performed and the aliasing process begins again on the reformed input line.
656Looping is prevented if the first word of the new text is the same as the old
657by flagging it to prevent further aliasing.
658Other loops are detected and cause an error.
659.Pp
660Note that the mechanism allows aliases to introduce parser metasyntax.
661Thus, we can `alias print \'pr \e!* \&| lpr\'' to make a command that
662.Ar pr Ns 's
663its arguments to the line printer.
664.Ss Variable substitution
665The shell maintains a set of variables, each of which has as value a list
666of zero or more words.
667Some of these variables are set by the shell or referred to by it.
668For instance, the
669.Ar argv
670variable is an image of the shell's argument list, and words of this
671variable's value are referred to in special ways.
672.Pp
673The values of variables may be displayed and changed by using the
674.Ar set
675and
676.Ar unset
677commands.
678Of the variables referred to by the shell a number are toggles;
679the shell does not care what their value is,
680only whether they are set or not.
681For instance, the
682.Ar verbose
683variable is a toggle that causes command input to be echoed.
684The setting of this variable results from the
685.Fl v
686command line option.
687.Pp
688Other operations treat variables numerically.
689The `@' command permits numeric calculations to be performed and the result
690assigned to a variable.
691Variable values are, however, always represented as (zero or more) strings.
692For the purposes of numeric operations, the null string is considered to be
693zero, and the second and additional words of multiword values are ignored.
694.Pp
695After the input line is aliased and parsed, and before each command
696is executed, variable substitution
697is performed keyed by `$' characters.
698This expansion can be prevented by preceding the `$' with a `\e' except
699within `"'s where it
700.Em always
701occurs, and within `\''s where it
702.Em never
703occurs.
704Strings quoted by `\*(ga' are interpreted later (see
705.Nm "Command substitution"
706below) so `$' substitution does not occur there until later, if at all.
707A `$' is passed unchanged if followed by a blank, tab, or end-of-line.
708.Pp
709Input/output redirections are recognized before variable expansion,
710and are variable expanded separately.
711Otherwise, the command name and entire argument list are expanded together.
712It is thus possible for the first (command) word (to this point) to generate
713more than one word, the first of which becomes the command name,
714and the rest of which become arguments.
715.Pp
716Unless enclosed in `"' or given the `:q' modifier the results of variable
717substitution may eventually be command and filename substituted.
718Within `"', a variable whose value consists of multiple words expands to a
719(portion of) a single word, with the words of the variables value
720separated by blanks.
721When the `:q' modifier is applied to a substitution
722the variable will expand to multiple words with each word separated
723by a blank and quoted to prevent later command or filename substitution.
724.Pp
725The following metasequences are provided for introducing variable values into
726the shell input.
727Except as noted, it is an error to reference a variable that is not set.
728.Pp
729.Bl -tag -width Ds -compact -offset indent
730.It $name
731.It ${name}
732Are replaced by the words of the value of variable
733.Ar name ,
734each separated by a blank.
735Braces insulate
736.Ar name
737from following characters that would otherwise be part of it.
738Shell variables have names consisting of up to 20 letters and digits
739starting with a letter.  The underscore character is considered a letter.
740If
741.Ar name
742is not a shell variable, but is set in the environment, then
743that value is returned (but
744.Nm :
745modifiers and the other forms
746given below are not available here).
747.It $name Ns Op selector
748.It ${name Ns [ selector ] }
749May be used to select only some of the words from the value of
750.Ar name .
751The selector is subjected to `$' substitution and may consist of a single
752number or two numbers separated by a `\-'.
753The first word of a variables value is numbered `1'.
754If the first number of a range is omitted it defaults to `1'.
755If the last number of a range is omitted it defaults to `$#name'.
756The selector `*' selects all words.
757It is not an error for a range to be empty if the second argument is omitted
758or in range.
759.It $#name
760.It ${#name}
761Gives the number of words in the variable.
762This is useful for later use in a
763`$argv[selector]'.
764.It $0
765Substitutes the name of the file from which command input is being read.
766An error occurs if the name is not known.
767.It $number
768.It ${number}
769Equivalent to
770`$argv[number]'.
771.It $*
772Equivalent to
773`$argv[*]'.
774The modifiers `:e', `:h', `:t', `:r', `:q' and `:x' may be applied to
775the substitutions above as may `:gh', `:gt' and `:gr'.
776If braces `{' '}' appear in the command form then the modifiers
777must appear within the braces.
778The current implementation allows only one `:' modifier on each `$' expansion.
779.El
780.Pp
781The following substitutions may not be modified with `:' modifiers.
782.Bl -tag -width Ds -compact -offset indent
783.It $?name
784.It ${?name}
785Substitutes the string `1' if name is set, `0' if it is not.
786.It $?0
787Substitutes `1' if the current input filename is known, `0' if it is not.
788.It \&$\&$\&
789Substitute the (decimal) process number of the (parent) shell.
790.It $!
791Substitute the (decimal) process number of the last background process
792started by this shell.
793.It $<
794Substitutes a line from the standard
795input, with no further interpretation.
796It can be used to read from the keyboard in a shell script.
797.El
798.Ss Command and filename substitution
799The remaining substitutions, command and filename substitution,
800are applied selectively to the arguments of builtin commands.
801By selectively, we mean that portions of expressions which are
802not evaluated are not subjected to these expansions.
803For commands that are not internal to the shell, the command
804name is substituted separately from the argument list.
805This occurs very late,
806after input-output redirection is performed, and in a child
807of the main shell.
808.Ss Command substitution
809Command substitution is shown by a command enclosed in `\*(ga'.
810The output from such a command is normally broken into separate words
811at blanks, tabs and newlines, with null words being discarded;
812this text then replaces the original string.
813Within `"'s, only newlines force new words; blanks and tabs are preserved.
814.Pp
815In any case, the single final newline does not force a new word.
816Note that it is thus possible for a command substitution to yield
817only part of a word, even if the command outputs a complete line.
818.Ss Filename substitution
819If a word contains any of the characters `*', `?', `[' or `{'
820or begins with the character `~', then that word is a candidate for
821filename substitution, also known as `globbing'.
822This word is then regarded as a pattern, and replaced with an alphabetically
823sorted list of file names that match the pattern.
824In a list of words specifying filename substitution it is an error for
825no pattern to match an existing file name, but it is not required
826for each pattern to match.
827Only the metacharacters `*', `?' and `[' imply pattern matching,
828the characters `~' and `{' being more akin to abbreviations.
829.Pp
830In matching filenames, the character `.' at the beginning of a filename
831or immediately following a `/', as well as the character `/' must
832be matched explicitly.
833The character `*' matches any string of characters, including the null
834string.
835The character `?' matches any single character.
836The sequence
837.Sq Op ...
838matches any one of the characters enclosed.
839Within
840.Sq Op ... ,
841a pair of characters separated by `\-' matches any character lexically between
842the two (inclusive).
843.Pp
844The character `~' at the beginning of a filename refers to home
845directories.
846Standing alone, i.e., `~' it expands to the invokers home directory as reflected
847in the value of the variable
848.Ar home .
849When followed by a name consisting of letters, digits and `\-' characters,
850the shell searches for a user with that name and substitutes their
851home directory;  thus `~ken' might expand to `/usr/ken' and `~ken/chmach'
852to `/usr/ken/chmach'.
853If the character `~' is followed by a character other than a letter or `/'
854or does not appear at the beginning of a word,
855it is left undisturbed.
856.Pp
857The metanotation `a{b,c,d}e' is a shorthand for `abe ace ade'.
858Left to right order is preserved, with results of matches being sorted
859separately at a low level to preserve this order.
860This construct may be nested.
861Thus, `~source/s1/{oldls,ls}.c' expands to
862`/usr/source/s1/oldls.c /usr/source/s1/ls.c'
863without chance of error
864if the home directory for `source' is `/usr/source'.
865Similarly `../{memo,*box}' might expand to `../memo ../box ../mbox'.
866(Note that `memo' was not sorted with the results of the match to `*box'.)
867As a special case `{', `}' and `{}' are passed undisturbed.
868.Ss Input/output
869The standard input and the standard output of a command may be redirected
870with the following syntax:
871.Pp
872.Bl -tag -width Ds -compact -offset indent
873.It < name
874Open file
875.Ar name
876(which is first variable, command and filename expanded) as the standard
877input.
878.It << word
879Read the shell input up to a line that is identical to
880.Ar word .
881.Ar Word
882is not subjected to variable, filename or command substitution,
883and each input line is compared to
884.Ar word
885before any substitutions are done on the input line.
886Unless a quoting `\e', `"', `\*(aa' or `\*(ga' appears in
887.Ar word ,
888variable and command substitution is performed on the intervening lines,
889allowing `\e' to quote `$', `\e' and `\*(ga'.
890Commands that are substituted have all blanks, tabs, and newlines
891preserved, except for the final newline which is dropped.
892The resultant text is placed in an anonymous temporary file that
893is given to the command as its standard input.
894.It > name
895.It >! name
896.It >& name
897.It >&! name
898The file
899.Ar name
900is used as the standard output.
901If the file does not exist then it is created;
902if the file exists, it is truncated; its previous contents are lost.
903.Pp
904If the variable
905.Ar noclobber
906is set, then the file must not exist or be a character special file (e.g., a
907terminal or `/dev/null') or an error results.
908This helps prevent accidental destruction of files.
909Here, the `!' forms can be used to suppress this check.
910.Pp
911The forms involving `&' route the standard error output into the specified
912file as well as the standard output.
913.Ar Name
914is expanded in the same way as `<' input filenames are.
915.It >> name
916.It >>& name
917.It >>! name
918.It >>&! name
919Uses file
920.Ar name
921as the standard output;
922like `>' but places output at the end of the file.
923If the variable
924.Ar noclobber
925is set, then it is an error for the file not to exist unless
926one of the `!' forms is given.
927Otherwise similar to `>'.
928.El
929.Pp
930A command receives the environment in which the shell was
931invoked as modified by the input-output parameters and
932the presence of the command in a pipeline.
933Thus, unlike some previous shells, commands run from a file of shell commands
934have no access to the text of the commands by default;
935instead they receive the original standard input of the shell.
936The `<<' mechanism should be used to present inline data.
937This permits shell command scripts to function as components of pipelines
938and allows the shell to block read its input.
939Note that the default standard input for a command run detached is
940.Ar not
941modified to be the empty file
942.Pa /dev/null ;
943instead the standard input
944remains as the original standard input of the shell.  If this is a terminal
945and if the process attempts to read from the terminal, then the process
946will block and the user will be notified (see
947.Sx Jobs
948above).
949.Pp
950The standard error output may be directed through
951a pipe with the standard output.
952Simply use the form `\&|&' instead of just `\&|'.
953.Ss Expressions
954Several of the builtin commands (to be described later)
955take expressions, in which the operators are similar to those of C, with
956the same precedence.
957These expressions appear in the
958.Nm @,
959.Ar exit ,
960.Ar if ,
961and
962.Ar while
963commands.
964The following operators are available:
965.Bd -ragged -offset indent
966\&|\&|  &&  \&| \*(ua  &  ==  !=  =~  !~  <=  >=
967<  > <<  >>  +  \-  *  /  %  !  ~  (  )
968.Ed
969.Pp
970Here the precedence increases to the right,
971`==' `!=' `=~' and `!~', `<=' `>=' `<' and `>', `<<' and `>>', `+' and `\-',
972`*' `/' and `%' being, in groups, at the same level.
973The `==' `!=' `=~' and `!~' operators compare their arguments as strings;
974all others operate on numbers.
975The operators `=~' and `!~' are like `!=' and `==' except that the right
976hand side is a
977.Ar pattern
978(containing, e.g., `*'s, `?'s and instances of `[...]')
979against which the left hand operand is matched.  This reduces the
980need for use of the
981.Ar switch
982statement in shell scripts when all that is really needed is pattern matching.
983.Pp
984Strings that begin with `0' are considered octal numbers.
985Null or missing arguments are considered `0'.
986The result of all expressions are strings,
987which represent decimal numbers.
988It is important to note that no two components of an expression can appear
989in the same word; except when adjacent to components of expressions that
990are syntactically significant to the parser (`&' `\&|' `<' `>' `(' `)'),
991they should be surrounded by spaces.
992.Pp
993Also available in expressions as primitive operands are command executions
994enclosed in `{' and `}'
995and file enquiries of the form
996.Fl l
997.Ar name
998where
999.Ic l
1000is one of:
1001.Bd -literal -offset indent
1002r	read access
1003w	write access
1004x	execute access
1005e	existence
1006o	ownership
1007z	zero size
1008f	plain file
1009d	directory
1010.Ed
1011.Pp
1012The specified name is command and filename expanded and then tested
1013to see if it has the specified relationship to the real user.
1014If the file does not exist or is inaccessible then all enquiries return
1015false, i.e., `0'.
1016Command executions succeed, returning true, i.e., `1',
1017if the command exits with status 0, otherwise they fail, returning
1018false, i.e., `0'.
1019If more detailed status information is required then the command
1020should be executed outside an expression and the variable
1021.Ar status
1022examined.
1023.Ss Control flow
1024The shell contains several commands that can be used to regulate the
1025flow of control in command files (shell scripts) and
1026(in limited but useful ways) from terminal input.
1027These commands all operate by forcing the shell to reread or skip in its
1028input and, because of the implementation, restrict the placement of some
1029of the commands.
1030.Pp
1031The
1032.Ic foreach ,
1033.Ic switch ,
1034and
1035.Ic while
1036statements, as well as the
1037.Ic if\-then\-else
1038form of the
1039.Ic if
1040statement require that the major keywords appear in a single simple command
1041on an input line as shown below.
1042.Pp
1043If the shell's input is not seekable,
1044the shell buffers up input whenever a loop is being read
1045and performs seeks in this internal buffer to accomplish the rereading
1046implied by the loop.
1047(To the extent that this allows, backward goto's will succeed on
1048non-seekable inputs.)
1049.Ss Builtin commands
1050Builtin commands are executed within the shell.
1051If a builtin command occurs as any component of a pipeline
1052except the last then it is executed in a subshell.
1053.Pp
1054.Bl -tag -width Ds -compact -offset indent
1055.It Ic alias
1056.It Ic alias Ar name
1057.It Ic alias Ar name wordlist
1058The first form prints all aliases.
1059The second form prints the alias for name.
1060The final form assigns the specified
1061.Ar wordlist
1062as the alias of
1063.Ar name ;
1064.Ar wordlist
1065is command and filename substituted.
1066.Ar Name
1067is not allowed to be
1068.Ar alias
1069or
1070.Ar unalias .
1071.Pp
1072.It Ic alloc
1073Shows the amount of dynamic memory acquired, broken down into used and
1074free memory.
1075With an argument shows the number of free and used blocks in each size
1076category.  The categories start at size 8 and double at each step.
1077This command's output may vary across system types, since
1078systems other than the VAX may use a different memory allocator.
1079.Pp
1080.It Ic bg
1081.It Ic bg \&% Ns Ar job ...
1082Puts the current or specified jobs into the background, continuing them
1083if they were stopped.
1084.Pp
1085.It Ic break
1086Causes execution to resume after the
1087.Ic end
1088of the nearest enclosing
1089.Ic foreach
1090or
1091.Ic while .
1092The remaining commands on the current line are executed.
1093Multi-level breaks are thus possible by writing them all on one line.
1094.Pp
1095.It Ic breaksw
1096Causes a break from a
1097.Ic switch ,
1098resuming after the
1099.Ic endsw .
1100.Pp
1101.It Ic case Ar label :
1102A label in a
1103.Ic switch
1104statement as discussed below.
1105.Pp
1106.It Ic cd
1107.It Ic cd Ar name
1108.It Ic chdir
1109.It Ic chdir Ar name
1110Change the shell's working directory to directory
1111.Ar name .
1112If no argument is given then change to the home directory of the user.
1113If
1114.Ar name
1115is not found as a subdirectory of the current directory (and does not begin
1116with `/', `./' or `../'), then each
1117component of the variable
1118.Ic cdpath
1119is checked to see if it has a subdirectory
1120.Ar name .
1121Finally, if all else fails but
1122.Ar name
1123is a shell variable whose value begins with `/', then this
1124is tried to see if it is a directory.
1125.Pp
1126.It Ic continue
1127Continue execution of the nearest enclosing
1128.Ic while
1129or
1130.Ic foreach .
1131The rest of the commands on the current line are executed.
1132.Pp
1133.It Ic default :
1134Labels the default case in a
1135.Ic switch
1136statement.
1137The default should come after all
1138.Ic case
1139labels.
1140.Pp
1141.It Ic dirs
1142Prints the directory stack; the top of the stack is at the left,
1143the first directory in the stack being the current directory.
1144.Pp
1145.It Ic echo Ar  wordlist
1146.It Ic echo Fl n Ar wordlist
1147The specified words are written to the shell's standard output, separated
1148by spaces, and terminated with a newline unless the
1149.Fl n
1150option is specified.
1151.Pp
1152.It Ic else
1153.It Ic end
1154.It Ic endif
1155.It Ic endsw
1156See the description of the
1157.Ic foreach ,
1158.Ic if ,
1159.Ic switch ,
1160and
1161.Ic while
1162statements below.
1163.Pp
1164.It Ic eval Ar arg ...
1165(As in
1166.Xr sh  1  . )
1167The arguments are read as input to the shell and the resulting
1168command(s) executed in the context of the current shell.
1169This is usually used to execute commands
1170generated as the result of command or variable substitution, since
1171parsing occurs before these substitutions.  See
1172.Xr tset  1
1173for an example of using
1174.Ic eval .
1175.Pp
1176.It Ic exec Ar command
1177The specified command is executed in place of the current shell.
1178.Pp
1179.It Ic exit
1180.It Ic exit Ar (expr )
1181The shell exits either with the value of the
1182.Ic status
1183variable (first form) or with the value of the specified
1184.Ic expr
1185(second form).
1186.Pp
1187.It Ic fg
1188.It Ic fg % Ns Ar job ...
1189Brings the current or specified jobs into the foreground, continuing them if
1190they were stopped.
1191.Pp
1192.It Ic foreach Ar name (wordlist)
1193.It ...
1194.It Ic end
1195The variable
1196.Ic name
1197is successively set to each member of
1198.Ic wordlist
1199and the sequence of commands between this command and the matching
1200.Ic end
1201are executed.
1202(Both
1203.Ic foreach
1204and
1205.Ic end
1206must appear alone on separate lines.)
1207The builtin command
1208.Ic continue
1209may be used to continue the loop prematurely and the builtin
1210command
1211.Ic break
1212to terminate it prematurely.
1213When this command is read from the terminal, the loop is read once
1214prompting with `?' before any statements in the loop are executed.
1215If you make a mistake typing in a loop at the terminal you can rub it out.
1216.Pp
1217.It Ic glob Ar wordlist
1218Like
1219.Ic echo
1220but no `\e' escapes are recognized and words are delimited
1221by null characters in the output.
1222Useful for programs that wish to use the shell to filename expand a list
1223of words.
1224.Pp
1225.It Ic goto Ar word
1226The specified
1227.Ic word
1228is filename and command expanded to yield a string of the form `label'.
1229The shell rewinds its input as much as possible
1230and searches for a line of the form `label:'
1231possibly preceded by blanks or tabs.
1232Execution continues after the specified line.
1233.Pp
1234.It Ic hashstat
1235Print a statistics line showing how effective the internal hash
1236table has been at locating commands (and avoiding
1237.Ic exec Ns \'s ) .
1238An
1239.Ic exec
1240is attempted for each component of the
1241.Em path
1242where the hash function indicates a possible hit, and in each component
1243that does not begin with a `/'.
1244.Pp
1245.It Ic history
1246.It Ic history Ar n
1247.It Ic history Fl r Ar n
1248.It Ic history Fl h Ar n
1249Displays the history event list; if
1250.Ar n
1251is given only the
1252.Ar n
1253most recent events are printed.
1254The
1255.Fl r
1256option reverses the order of printout to be most recent first
1257instead of oldest first.
1258The
1259.Fl h
1260option causes the history list to be printed without leading numbers.
1261This format produces files suitable for sourcing using the \-h
1262option to
1263.Ic source  .
1264.Pp
1265.It Ic if ( Ar expr ) No command
1266If the specified expression evaluates true, then the single
1267.Ar command
1268with arguments is executed.
1269Variable substitution on
1270.Ar command
1271happens early, at the same
1272time it does for the rest of the
1273.Ic if
1274command.
1275.Ar Command
1276must be a simple command, not
1277a pipeline, a command list, or a parenthesized command list.
1278Input/output redirection occurs even if
1279.Ar expr
1280is false, i.e., when command is
1281.Sy not
1282executed (this is a bug).
1283.Pp
1284.It Ic if ( Ar expr ) Ic then
1285.It ...
1286.It Ic else if ( Ar expr2 ) Ic then
1287.It ...
1288.It Ic else
1289.It ...
1290.It Ic endif
1291If the specified
1292.Ar expr
1293is true then the commands up to the first
1294.Ic else
1295are executed; otherwise if
1296.Ar expr2
1297is true then the commands up to the
1298second
1299.Ic else
1300are executed, etc.
1301Any number of
1302.Ic else-if
1303pairs are possible; only one
1304.Ic endif
1305is needed.
1306The
1307.Ic else
1308part is likewise optional.
1309(The words
1310.Ic else
1311and
1312.Ic endif
1313must appear at the beginning of input lines;
1314the
1315.Ic if
1316must appear alone on its input line or after an
1317.Ic else . )
1318.Pp
1319.It Ic jobs
1320.It Ic jobs Fl l
1321Lists the active jobs; the
1322.Fl l
1323option lists process id's in addition to the normal information.
1324.Pp
1325.It Ic kill % Ns Ar job
1326.It Ic kill Ar pid
1327.It Ic kill Fl sig Ar pid ...
1328.It Ic kill Fl l
1329Sends either the TERM (terminate) signal or the
1330specified signal to the specified jobs or processes.
1331Signals are either given by number or by names (as given in
1332.Pa /usr/include/signal.h,
1333stripped of the prefix ``SIG'').
1334The signal names are listed by ``kill \-l''.
1335There is no default, just saying `kill' does not
1336send a signal to the current job.
1337If the signal being sent is TERM (terminate) or HUP (hangup),
1338then the job or process will be sent a CONT (continue) signal as well.
1339.Pp
1340.It Ic limit
1341.It Ic limit Ar resource
1342.It Ic limit Ar resource maximum-use
1343.It Ic limit Fl h
1344.It Ic limit Fl h Ar resource
1345.It Ic limit Fl h Ar resource maximum-use
1346Limits the consumption by the current process and each process
1347it creates to not individually exceed
1348.Ar maximum-use
1349on the
1350specified
1351.Ar resource  .
1352If no
1353.Ar maximum-use
1354is given, then
1355the current limit is printed; if no
1356.Ar resource
1357is given, then
1358all limitations are given.  If the
1359.Fl h
1360flag is given, the hard limits are used instead of the current
1361limits.  The hard limits impose a ceiling on the values of
1362the current limits.  Only the super-user may raise the hard limits,
1363but a user may lower or raise the current limits within the legal range.
1364.Pp
1365Resources controllable currently include
1366.Ar cputime
1367(the maximum
1368number of cpu-seconds to be used by each process),
1369.Ar filesize
1370(the largest single file that can be created),
1371.Ar datasize
1372(the maximum growth of the data+stack region via
1373.Xr sbrk  2
1374beyond the end of the program text),
1375.Ar stacksize
1376(the maximum
1377size of the automatically-extended stack region), and
1378.Ar coredumpsize
1379(the size of the largest core dump that will be created).
1380.Pp
1381The
1382.Ar maximum-use
1383may be given as a (floating point or integer)
1384number followed by a scale factor.  For all limits other than
1385.Ar cputime
1386the default scale is `k' or `kilobytes' (1024 bytes);
1387a scale factor of `m' or `megabytes' may also be used.
1388For
1389.Ar cputime
1390the default scale is `seconds';
1391a scale factor of `m' for minutes
1392or `h' for hours, or a time of the form `mm:ss' giving minutes
1393and seconds also may be used.
1394.Pp
1395For both
1396.Ar resource
1397names and scale factors, unambiguous prefixes
1398of the names suffice.
1399.Pp
1400.It Ic login
1401Terminate a login shell, replacing it with an instance of
1402.Pa /bin/login.
1403This is one way to log off, included for compatibility with
1404.Xr sh  1  .
1405.Pp
1406.It Ic logout
1407Terminate a login shell.
1408Especially useful if
1409.Ic ignoreeof
1410is set.
1411.Pp
1412.It Ic nice
1413.It Ic nice Ar +number
1414.It Ic nice Ar command
1415.It Ic nice Ar +number command
1416The first form sets the
1417scheduling priority
1418for this shell to 4.
1419The second form sets the
1420priority
1421to the given
1422.Ar number .
1423The final two forms run command at priority 4 and
1424.Ar number
1425respectively.
1426The greater the number, the less cpu the process will get.
1427The super-user may specify negative priority by using `nice \-number ...'.
1428.Ar Command
1429is always executed in a sub-shell, and the restrictions
1430placed on commands in simple
1431.Ic if
1432statements apply.
1433.Pp
1434.It Ic nohup
1435.It Ic nohup Ar command
1436The first form can be used in shell scripts to cause hangups to be
1437ignored for the remainder of the script.
1438The second form causes the specified command to be run with hangups
1439ignored.
1440All processes detached with `&' are effectively
1441.Ic nohup Ns \'ed .
1442.Pp
1443.It Ic notify
1444.It Ic notify % Ns Ar job ...
1445Causes the shell to notify the user asynchronously when the status of the
1446current or specified jobs change; normally notification is presented
1447before a prompt.  This is automatic if the shell variable
1448.Ic notify
1449is set.
1450.Pp
1451.It Ic onintr
1452.It Ic onintr Fl
1453.It Ic onintr Ar label
1454Control the action of the shell on interrupts.
1455The first form restores the default action of the shell on interrupts
1456which is to terminate shell scripts or to return to the terminal command
1457input level.
1458The second form `onintr \-' causes all interrupts to be ignored.
1459The final form causes the shell to execute a `goto label' when
1460an interrupt is received or a child process terminates because
1461it was interrupted.
1462.Pp
1463In any case, if the shell is running detached and interrupts are
1464being ignored, all forms of
1465.Ic onintr
1466have no meaning and interrupts
1467continue to be ignored by the shell and all invoked commands.
1468Finally
1469.Ic onintr
1470statements are ignored in the system startup files where interrupts
1471are disabled (/etc/csh.cshrc, /etc/csh.login).
1472.Pp
1473.It Ic popd
1474.It Ic popd Ar +n
1475Pops the directory stack, returning to the new top directory.
1476With an argument
1477.Ns \`+ Ar n Ns \'
1478discards the
1479.Ar n Ns \'th
1480entry in the stack.
1481The members of the directory stack are numbered from the top starting at 0.
1482.Pp
1483.It Ic pushd
1484.It Ic pushd Ar name
1485.It Ic pushd Ar n
1486With no arguments,
1487.Ic pushd
1488exchanges the top two elements of the directory stack.
1489Given a
1490.Ar name
1491argument,
1492.Ic pushd
1493changes to the new directory (ala
1494.Ic cd )
1495and pushes the old current working directory
1496(as in
1497.Ic csw )
1498onto the directory stack.
1499With a numeric argument,
1500.Ic pushd
1501rotates the
1502.Ar n Ns \'th
1503argument of the directory
1504stack around to be the top element and changes to it.  The members
1505of the directory stack are numbered from the top starting at 0.
1506.Pp
1507.It Ic rehash
1508Causes the internal hash table of the contents of the directories in
1509the
1510.Ic path
1511variable to be recomputed.  This is needed if new commands are added
1512to directories in the
1513.Ic path
1514while you are logged in.  This should only be necessary if you add
1515commands to one of your own directories, or if a systems programmer
1516changes the contents of a system directory.
1517.Pp
1518.It Ic repeat Ar count command
1519The specified
1520.Ar command
1521which is subject to the same restrictions
1522as the
1523.Ar command
1524in the one line
1525.Ic if
1526statement above,
1527is executed
1528.Ar count
1529times.
1530I/O redirections occur exactly once, even if
1531.Ar count
1532is 0.
1533.Pp
1534.It Ic set
1535.It Ic set Ar name
1536.It Ic set Ar name Ns =word
1537.It Ic set Ar name[index] Ns =word
1538.It Ic set Ar name Ns =(wordlist)
1539The first form of the command shows the value of all shell variables.
1540Variables that have other than a single word as their
1541value print as a parenthesized word list.
1542The second form sets
1543.Ar name
1544to the null string.
1545The third form sets
1546.Ar name
1547to the single
1548.Ar word .
1549The fourth form sets
1550the
1551.Ar index Ns 'th
1552component of
1553.Ar name
1554to
1555.Ar word ;
1556this component must already exist.
1557The final form sets
1558.Ar name
1559to the list of words in
1560.Ar wordlist .
1561The value is always command and filename expanded.
1562.Pp
1563These arguments may be repeated to set multiple values in a single set command.
1564Note however, that variable expansion happens for all arguments before any
1565setting occurs.
1566.Pp
1567.It Ic setenv
1568.It Ic setenv Ar name
1569.It Ic setenv Ar name value
1570The first form lists all current environment variables.
1571It is equivalent to
1572.Xr printenv 1 .
1573The last form sets the value of environment variable
1574.Ar name
1575to be
1576.Ar value ,
1577a single string.  The second form sets
1578.Ar name
1579to an empty string.
1580The most commonly used environment variables
1581.Ev USER ,
1582.Ev TERM ,
1583and
1584.Ev PATH
1585are automatically imported to and exported from the
1586.Nm csh
1587variables
1588.Ar user ,
1589.Ar term ,
1590and
1591.Ar path ;
1592there is no need to use
1593.Ic setenv
1594for these.
1595.Pp
1596.It Ic shift
1597.It Ic shift Ar variable
1598The members of
1599.Ic argv
1600are shifted to the left, discarding
1601.Ic argv Ns Bq 1 .
1602It is an error for
1603.Ic argv
1604not to be set or to have less than one word as value.
1605The second form performs the same function on the specified variable.
1606.Pp
1607.It Ic source Ar name
1608.It Ic source Fl h Ar name
1609The shell reads commands from
1610.Ar name .
1611.Ic Source
1612commands may be nested; if they are nested too deeply the shell may
1613run out of file descriptors.
1614An error in a
1615.Ic source
1616at any level terminates all nested
1617.Ic source
1618commands.
1619Normally input during
1620.Ic source
1621commands is not placed on the history list;
1622the \-h option causes the commands to be placed on the
1623history list without being executed.
1624.Pp
1625.It Ic stop
1626.It Ic stop % Ns Ar job ...
1627Stops the current or specified jobs that are executing in the background.
1628.Pp
1629.It Ic suspend
1630Causes the shell to stop in its tracks, much as if it had been sent a stop
1631signal with
1632.Ic ^Z .
1633This is most often used to stop shells started by
1634.Xr su  1 .
1635.Pp
1636.It Ic switch Ar (string)
1637.It Ic case Ar str1 :
1638.It \ \ \ \ \&...
1639.It Ic \ \ \ \ breaksw
1640.It \ \ \ \ \&...
1641.It Ic default :
1642.It \ \ \ \ \&...
1643.It Ic \ \ \ \ breaksw
1644.It Ic endsw
1645Each case label is successively matched against the specified
1646.Ar string
1647which is first command and filename expanded.
1648The file metacharacters `*', `?' and `[...]'
1649may be used in the case labels,
1650which are variable expanded.
1651If none of the labels match before the `default' label is found, then
1652the execution begins after the default label.
1653Each case label and the default label must appear at the beginning of a line.
1654The command
1655.Ic breaksw
1656causes execution to continue after the
1657.Ic endsw .
1658Otherwise control may fall through case labels and the default label as in C.
1659If no label matches and there is no default, execution continues after
1660the
1661.Ic endsw .
1662.Pp
1663.It Ic time
1664.It Ic time Ar command
1665With no argument, a summary of time used by this shell and its children
1666is printed.
1667If arguments are given
1668the specified simple command is timed and a time summary
1669as described under the
1670.Ic time
1671variable is printed.  If necessary, an extra shell is created to print the time
1672statistic when the command completes.
1673.Pp
1674.It Ic umask
1675.It Ic umask Ar value
1676The file creation mask is displayed (first form) or set to the specified
1677value (second form).  The mask is given in octal.  Common values for
1678the mask are 002 giving all access to the group and read and execute
1679access to others or 022 giving all access except write access for
1680users in the group or others.
1681.Pp
1682.It Ic unalias Ar pattern
1683All aliases whose names match the specified pattern are discarded.
1684Thus all aliases are removed by `unalias *'.
1685It is not an error for nothing to be
1686.Ic unaliased .
1687.Pp
1688.It Ic unhash
1689Use of the internal hash table to speed location of executed programs
1690is disabled.
1691.Pp
1692.It Ic unlimit
1693.It Ic unlimit Ar  resource
1694.It Ic unlimit Fl h
1695.It Ic unlimit Fl h Ar resource
1696Removes the limitation on
1697.Ar resource  .
1698If no
1699.Ar resource
1700is specified, then all
1701.Ar resource
1702limitations are removed.  If
1703.Fl h
1704is given, the corresponding hard limits are removed.  Only the
1705super-user may do this.
1706.Pp
1707.It Ic unset Ar pattern
1708All variables whose names match the specified pattern are removed.
1709Thus all variables are removed by `unset *'; this has noticeably
1710distasteful side-effects.
1711It is not an error for nothing to be
1712.Ic unset .
1713.Pp
1714.It Ic unsetenv Ar pattern
1715Removes all variables whose name match the specified pattern from the
1716environment.  See also the
1717.Ic setenv
1718command above and
1719.Xr printenv  1  .
1720.Pp
1721.It Ic wait
1722Wait for all background jobs.
1723If the shell is interactive, then an interrupt can disrupt the wait.
1724After the interrupt, the shell prints names and job numbers of all jobs
1725known to be outstanding.
1726.It Ic which Ar command
1727Displays the resolved command that will be executed by the shell.
1728.Pp
1729.It Ic while Ar (expr)
1730.It \&...
1731.It Ic end
1732While the specified expression evaluates non-zero, the commands between
1733the
1734.Ic while
1735and the matching
1736.Ic end
1737are evaluated.
1738.Ic Break
1739and
1740.Ic continue
1741may be used to terminate or continue the loop prematurely.
1742(The
1743.Ic while
1744and
1745.Ic end
1746must appear alone on their input lines.)
1747Prompting occurs here the first time through the loop as for the
1748.Ic foreach
1749statement if the input is a terminal.
1750.Pp
1751.It Ic % Ns Ar job
1752Brings the specified job into the foreground.
1753.Pp
1754.It Ic % Ns Ar job Ic &
1755Continues the specified job in the background.
1756.Pp
1757.It Ic @
1758.It Ic @ Ar name Ns = expr
1759.It Ic @ Ar name[index] Ns = expr
1760The first form prints the values of all the shell variables.
1761The second form sets the specified
1762.Ar name
1763to the value of
1764.Ar expr .
1765If the expression contains `<', `>', `&' or `|' then at least
1766this part of the expression must be placed within `(' `)'.
1767The third form assigns the value of
1768.Ar expr
1769to the
1770.Ar index Ns 'th
1771argument of
1772.Ar name .
1773Both
1774.Ar name
1775and its
1776.Ar index Ns 'th
1777component must already exist.
1778.El
1779.Pp
1780The operators `*=', `+=', etc are available as in C.
1781The space separating the name from the assignment operator is optional.
1782Spaces are, however, mandatory in separating components of
1783.Ar expr
1784which would otherwise be single words.
1785.Pp
1786Special postfix `+\|+' and `\-\|\-' operators increment and decrement
1787.Ar name
1788respectively, i.e., `@  i++'.
1789.Ss Pre-defined and environment variables
1790The following variables have special meaning to the shell.
1791Of these,
1792.Ar argv ,
1793.Ar cwd,
1794.Ar home ,
1795.Ar path,
1796.Ar prompt ,
1797.Ar shell
1798and
1799.Ar status
1800are always set by the shell.
1801Except for
1802.Ar cwd
1803and
1804.Ar status ,
1805this setting occurs only at initialization;
1806these variables will not then be modified unless done
1807explicitly by the user.
1808.Pp
1809The shell copies the environment variable
1810.Ev USER
1811into the variable
1812.Ar user ,
1813.Ev TERM
1814into
1815.Ar term ,
1816and
1817.Ev HOME
1818into
1819.Ar home ,
1820and copies these back into the environment whenever the normal
1821shell variables are reset.
1822The environment variable
1823.Ev PATH
1824is likewise handled; it is not
1825necessary to worry about its setting other than in the file
1826.Ar \&.cshrc
1827as inferior
1828.Nm csh
1829processes will import the definition of
1830.Ar path
1831from the environment, and re-export it if you then change it.
1832.Bl -tag -width histchars
1833.It Ic argv
1834Set to the arguments to the shell, it is from this variable that
1835positional parameters are substituted, i.e., `$1' is replaced by
1836`$argv[1]',
1837etc.
1838.It Ic cdpath
1839Gives a list of alternative directories searched to find subdirectories
1840in
1841.Ar chdir
1842commands.
1843.It Ic cwd
1844The full pathname of the current directory.
1845.It Ic echo
1846Set when the
1847.Fl x
1848command line option is given.
1849Causes each command and its arguments
1850to be echoed just before it is executed.
1851For non-builtin commands all expansions occur before echoing.
1852Builtin commands are echoed before command and filename substitution,
1853since these substitutions are then done selectively.
1854.It Ic filec
1855Enable file name completion.
1856.It Ic histchars
1857Can be given a string value to change the characters used in history
1858substitution.  The first character of its value is used as the
1859history substitution character, replacing the default character `!'.
1860The second character of its value replaces the character `\(ua' in
1861quick substitutions.
1862.It Ic histfile
1863Can be set to the pathname where history is going to be saved/restored.
1864.It Ic history
1865Can be given a numeric value to control the size of the history list.
1866Any command that has been referenced in this many events will not be
1867discarded.
1868Too large values of
1869.Ar history
1870may run the shell out of memory.
1871The last executed command is always saved on the history list.
1872.It Ic home
1873The home directory of the invoker, initialized from the environment.
1874The filename expansion of
1875.Sq Pa ~
1876refers to this variable.
1877.It Ic ignoreeof
1878If set the shell ignores
1879end-of-file from input devices which are terminals.
1880This prevents shells from accidentally being killed by control-D's.
1881.It Ic mail
1882The files where the shell checks for mail.
1883This checking is done after each command completion that will
1884result in a prompt,
1885if a specified interval has elapsed.
1886The shell says `You have new mail.'
1887if the file exists with an access time not greater than its modify time.
1888.Pp
1889If the first word of the value of
1890.Ar mail
1891is numeric it specifies a different mail checking interval, in seconds,
1892than the default, which is 10 minutes.
1893.Pp
1894If multiple mail files are specified, then the shell says
1895`New mail in
1896.Ar name Ns '
1897when there is mail in the file
1898.Ar name .
1899.It Ic noclobber
1900As described in the section on
1901.Sx input/output ,
1902restrictions are placed on output redirection to insure that
1903files are not accidentally destroyed, and that `>>' redirections
1904refer to existing files.
1905.It Ic noglob
1906If set, filename expansion is inhibited.
1907This inhibition is most useful in shell scripts that
1908 are not dealing with filenames,
1909or after a list of filenames has been obtained and further expansions
1910are not desirable.
1911.It Ic nonomatch
1912If set, it is not an error for a filename expansion to not match any
1913existing files; instead the primitive pattern is returned.
1914It is still an error for the primitive pattern to be malformed, i.e.,
1915`echo ['
1916still gives an error.
1917.It Ic notify
1918If set, the shell notifies asynchronously of job completions;
1919the default is to present job completions just before printing
1920a prompt.
1921.It Ic path
1922Each word of the path variable specifies a directory in which
1923commands are to be sought for execution.
1924A null word specifies the current directory.
1925If there is no
1926.Ar path
1927variable then only full path names will execute.
1928The usual search path is `.', `/bin' and `/usr/bin', but this
1929may vary from system to system.
1930For the super-user the default search path is `/etc', `/bin' and `/usr/bin'.
1931A shell that is given neither the
1932.Fl c
1933nor the
1934.Fl t
1935option will normally hash the contents of the directories in the
1936.Ar path
1937variable after reading
1938.Ar \&.cshrc ,
1939and each time the
1940.Ar path
1941variable is reset.  If new commands are added to these directories
1942while the shell is active, it may be necessary to do a
1943.Ic rehash
1944or the commands may not be found.
1945.It Ic prompt
1946The string that is printed before each command is read from
1947an interactive terminal input.
1948If a `!' appears in the string it will be replaced by the current event number
1949unless a preceding `\e' is given.
1950Default is `% ', or `# ' for the super-user.
1951.It Ic savehist
1952Is given a numeric value to control the number of entries of the
1953history list that are saved in ~/.history when the user logs out.
1954Any command that has been referenced in this many events will be saved.
1955During start up the shell sources ~/.history into the history list
1956enabling history to be saved across logins.
1957Too large values of
1958.Ar savehist
1959will slow down the shell during start up.
1960If
1961.Ar savehist
1962is just set, the shell will use the value of
1963.Ar history.
1964.It Ic shell
1965The file in which the shell resides.
1966This variable is used in forking shells to interpret files that have execute
1967bits set, but which are not executable by the system.
1968(See the description of
1969.Sx Non-builtin Command Execution
1970below.)
1971Initialized to the (system-dependent) home of the shell.
1972.It Ic status
1973The status returned by the last command.
1974If it terminated abnormally, then 0200 is added to the status.
1975Builtin commands that fail return exit status `1',
1976all other builtin commands set status to `0'.
1977.It Ic time
1978Controls automatic timing of commands.
1979If set, then any command that takes more than this many cpu seconds
1980will cause a line giving user, system, and real times and a utilization
1981percentage which is the ratio of user plus system times to real time
1982to be printed when it terminates.
1983.It Ic verbose
1984Set by the
1985.Fl v
1986command line option, causes the words of each command to be printed
1987after history substitution.
1988.El
1989.Ss Non-builtin command execution
1990When a command to be executed is found to not be a builtin command
1991the shell attempts to execute the command via
1992.Xr execve  2  .
1993Each word in the variable
1994.Ar path
1995names a directory from which the shell will attempt to execute the command.
1996If it is given neither a
1997.Fl c
1998nor a
1999.Fl t
2000option, the shell will hash the names in these directories into an internal
2001table so that it will only try an
2002.Ic exec
2003in a directory if there is a possibility that the command resides there.
2004This shortcut greatly speeds command location when many directories
2005are present in the search path.
2006If this mechanism has been turned off (via
2007.Ic unhash ) ,
2008or if the shell was given a
2009.Fl c
2010or
2011.Fl t
2012argument, and in any case for each directory component of
2013.Ar path
2014that does not begin with a `/',
2015the shell concatenates with the given command name to form a path name
2016of a file which it then attempts to execute.
2017.Pp
2018Parenthesized commands are always executed in a subshell.
2019Thus
2020.Pp
2021.Dl (cd ; pwd) ; pwd
2022.Pp
2023prints the
2024.Ar home
2025directory; leaving you where you were (printing this after the home directory),
2026while
2027.Pp
2028.Dl cd ; pwd
2029.Pp
2030leaves you in the
2031.Ar home
2032directory.
2033Parenthesized commands are most often used to prevent
2034.Ic chdir
2035from affecting the current shell.
2036.Pp
2037If the file has execute permissions but is not an
2038executable binary to the system, then it is assumed to be a
2039file containing shell commands and a new shell is spawned to read it.
2040.Pp
2041If there is an
2042.Ic alias
2043for
2044.Ic shell
2045then the words of the alias will be prepended to the argument list to form
2046the shell command.
2047The first word of the
2048.Ic alias
2049should be the full path name of the shell
2050(e.g., `$shell').
2051Note that this is a special, late occurring, case of
2052.Ic alias
2053substitution,
2054and only allows words to be prepended to the argument list without change.
2055.Ss Signal handling
2056The shell normally ignores
2057.Ar quit
2058signals.
2059Jobs running detached (either by
2060.Ic \&&
2061or the
2062.Ic bg
2063or
2064.Ic %... &
2065commands) are immune to signals generated from the keyboard, including
2066hangups.
2067Other signals have the values which the shell inherited from its parent.
2068The shell's handling of interrupts and terminate signals
2069in shell scripts can be controlled by
2070.Ic onintr .
2071Login shells catch the
2072.Ar terminate
2073signal; otherwise this signal is passed on to children from the state in the
2074shell's parent.
2075Interrupts are not allowed when a login shell is reading the file
2076.Pa \&.logout .
2077.Sh AUTHOR
2078William Joy.
2079Job control and directory stack features first implemented by J.E. Kulp of
2080IIASA, Laxenburg, Austria,
2081with different syntax than that used now.
2082File name completion code written by Ken Greer, HP Labs.
2083Eight-bit implementation Christos S. Zoulas, Cornell University.
2084.Sh FILES
2085.Bl -tag -width /etc/passwd -compact
2086.It Pa ~/.cshrc
2087Read at beginning of execution by each shell.
2088.It Pa ~/.login
2089Read by login shell, after `.cshrc' at login.
2090.It Pa ~/.logout
2091Read by login shell, at logout.
2092.It Pa /bin/sh
2093Standard shell, for shell scripts not starting with a `#'.
2094.It Pa /tmp/sh*
2095Temporary file for `<<'.
2096.It Pa /etc/passwd
2097Source of home directories for `~name'.
2098.El
2099.Sh LIMITATIONS
2100Word lengths \-
2101Words can be no longer than 1024 characters.
2102The system limits argument lists to 10240 characters.
2103The number of arguments to a command that involves filename expansion
2104is limited to 1/6'th the number of characters allowed in an argument list.
2105Command substitutions may substitute no more characters than are
2106allowed in an argument list.
2107To detect looping, the shell restricts the number of
2108.Ic alias
2109substitutions on a single line to 20.
2110.Sh SEE ALSO
2111.Xr sh 1 ,
2112.Xr access 2 ,
2113.Xr execve 2 ,
2114.Xr fork 2 ,
2115.Xr pipe 2 ,
2116.Xr setrlimit 2 ,
2117.Xr sigaction 2 ,
2118.Xr umask 2 ,
2119.Xr wait 2 ,
2120.Xr killpg 3 ,
2121.Xr tty 4 ,
2122.Xr a.out 5 ,
2123.Xr environ 7 ,
2124.br
2125.Em An introduction to the C shell
2126.Sh HISTORY
2127.Nm Csh
2128appeared in
2129.Bx 3 .
2130It
2131was a first implementation of a command language interpreter
2132incorporating a history mechanism (see
2133.Sx History Substitutions ) ,
2134job control facilities (see
2135.Sx Jobs ) ,
2136interactive file name
2137and user name completion (see
2138.Sx File Name Completion ) ,
2139and a C-like syntax.
2140There are now many shells that also have these mechanisms, plus
2141a few more (and maybe some bugs too), which are available through the
2142usenet.
2143.Sh BUGS
2144When a command is restarted from a stop,
2145the shell prints the directory it started in if this is different
2146from the current directory; this can be misleading (i.e., wrong)
2147as the job may have changed directories internally.
2148.Pp
2149Shell builtin functions are not stoppable/restartable.
2150Command sequences of the form `a ; b ; c' are also not handled gracefully
2151when stopping is attempted.  If you suspend `b', the shell will
2152immediately execute `c'.  This is especially noticeable if this
2153expansion results from an
2154.Ar alias .
2155It suffices to place the sequence of commands in ()'s to force it to
2156a subshell, i.e., `( a ; b ; c )'.
2157.Pp
2158Control over tty output after processes are started is primitive;
2159perhaps this will inspire someone to work on a good virtual
2160terminal interface.  In a virtual terminal interface much more
2161interesting things could be done with output control.
2162.Pp
2163Alias substitution is most often used to clumsily simulate shell procedures;
2164shell procedures should be provided instead of aliases.
2165.Pp
2166Commands within loops, prompted for by `?', are not placed on the
2167.Ic history
2168list.
2169Control structure should be parsed instead of being recognized as built-in
2170commands.  This would allow control commands to be placed anywhere,
2171to be combined with `\&|', and to be used with `&' and `;' metasyntax.
2172.Pp
2173It should be possible to use the `:' modifiers on the output of command
2174substitutions.
2175.Pp
2176The way the
2177.Ic filec
2178facility is implemented is ugly and expensive.
2179