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