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