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