]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - bin/sh/sh.1
MFC r201053: sh: Various warning fixes (from WARNS=6 NO_WERROR=1):
[FreeBSD/stable/8.git] / bin / sh / sh.1
1 .\"-
2 .\" Copyright (c) 1991, 1993
3 .\"     The Regents of the University of California.  All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Kenneth Almquist.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     from: @(#)sh.1  8.6 (Berkeley) 5/4/95
33 .\" $FreeBSD$
34 .\"
35 .Dd September 10, 2010
36 .Dt SH 1
37 .Os
38 .Sh NAME
39 .Nm sh
40 .Nd command interpreter (shell)
41 .Sh SYNOPSIS
42 .Nm
43 .Op Fl /+abCEefIimnPpsTuVvx
44 .Op Fl /+o Ar longname
45 .Op Fl c Ar string
46 .Op Ar arg ...
47 .Sh DESCRIPTION
48 The
49 .Nm
50 utility is the standard command interpreter for the system.
51 The current version of
52 .Nm
53 is in the process of being changed to
54 conform with the
55 .St -p1003.2
56 specification for the shell.
57 This version has many features which make
58 it appear
59 similar in some respects to the Korn shell, but it is not a Korn
60 shell clone like
61 .Nm pdksh .
62 Only features
63 designated by
64 .Tn POSIX ,
65 plus a few Berkeley extensions, are being
66 incorporated into this shell.
67 This man page is not intended to be a tutorial nor a complete
68 specification of the shell.
69 .Ss Overview
70 The shell is a command that reads lines from
71 either a file or the terminal, interprets them, and
72 generally executes other commands.
73 It is the program that is started when a user logs into the system,
74 although a user can select a different shell with the
75 .Xr chsh 1
76 command.
77 The shell
78 implements a language that has flow control constructs,
79 a macro facility that provides a variety of features in
80 addition to data storage, along with built-in history and line
81 editing capabilities.
82 It incorporates many features to
83 aid interactive use and has the advantage that the interpretative
84 language is common to both interactive and non-interactive
85 use (shell scripts).
86 That is, commands can be typed directly
87 to the running shell or can be put into a file,
88 which can be executed directly by the shell.
89 .Ss Invocation
90 .\"
91 .\" XXX This next sentence is incredibly confusing.
92 .\"
93 If no arguments are present and if the standard input of the shell
94 is connected to a terminal
95 (or if the
96 .Fl i
97 option is set),
98 the shell is considered an interactive shell.
99 An interactive shell
100 generally prompts before each command and handles programming
101 and command errors differently (as described below).
102 When first starting, the shell inspects argument 0, and
103 if it begins with a dash
104 .Pq Ql - ,
105 the shell is also considered a login shell.
106 This is normally done automatically by the system
107 when the user first logs in.
108 A login shell first reads commands
109 from the files
110 .Pa /etc/profile
111 and then
112 .Pa .profile
113 in a user's home directory,
114 if they exist.
115 If the environment variable
116 .Ev ENV
117 is set on entry to a shell, or is set in the
118 .Pa .profile
119 of a login shell, the shell then reads commands from the file named in
120 .Ev ENV .
121 Therefore, a user should place commands that are to be executed only
122 at login time in the
123 .Pa .profile
124 file, and commands that are executed for every shell inside the
125 .Ev ENV
126 file.
127 The user can set the
128 .Ev ENV
129 variable to some file by placing the following line in the file
130 .Pa .profile
131 in the home directory,
132 substituting for
133 .Pa .shinit
134 the filename desired:
135 .Pp
136 .Dl "ENV=$HOME/.shinit; export ENV"
137 .Pp
138 The first non-option argument specified on the command line
139 will be treated as the
140 name of a file from which to read commands (a shell script), and
141 the remaining arguments are set as the positional parameters
142 of the shell
143 .Li ( $1 , $2 ,
144 etc.).
145 Otherwise, the shell reads commands
146 from its standard input.
147 .Pp
148 Unlike older versions of
149 .Nm
150 the
151 .Ev ENV
152 script is only sourced on invocation of interactive shells.
153 This
154 closes a well-known, and sometimes easily exploitable security
155 hole related to poorly thought out
156 .Ev ENV
157 scripts.
158 .Ss Argument List Processing
159 All of the single letter options to
160 .Nm
161 have a corresponding long name,
162 with the exception of
163 .Fl c
164 and
165 .Fl /+o .
166 These long names are provided next to the single letter options
167 in the descriptions below.
168 The long name for an option may be specified as an argument to the
169 .Fl /+o
170 option of
171 .Nm .
172 Once the shell is running,
173 the long name for an option may be specified as an argument to the
174 .Fl /+o
175 option of the
176 .Ic set
177 built-in command
178 (described later in the section called
179 .Sx Built-in Commands ) .
180 Introducing an option with a dash
181 .Pq Ql -
182 enables the option,
183 while using a plus
184 .Pq Ql +
185 disables the option.
186 A
187 .Dq Li --
188 or plain
189 .Ql -
190 will stop option processing and will force the remaining
191 words on the command line to be treated as arguments.
192 The
193 .Fl /+o
194 and
195 .Fl c
196 options do not have long names.
197 They take arguments and are described after the single letter options.
198 .Bl -tag -width indent
199 .It Fl a Li allexport
200 Flag variables for export when assignments are made to them.
201 .It Fl b Li notify
202 Enable asynchronous notification of background job
203 completion.
204 (UNIMPLEMENTED)
205 .It Fl C Li noclobber
206 Do not overwrite existing files with
207 .Ql > .
208 .It Fl E Li emacs
209 Enable the built-in
210 .Xr emacs 1
211 command line editor (disables the
212 .Fl V
213 option if it has been set).
214 .It Fl e Li errexit
215 Exit immediately if any untested command fails in non-interactive mode.
216 The exit status of a command is considered to be
217 explicitly tested if the command is part of the list used to control
218 an
219 .Ic if , elif , while ,
220 or
221 .Ic until ;
222 if the command is the left
223 hand operand of an
224 .Dq Li &&
225 or
226 .Dq Li ||
227 operator; or if the command is a pipeline preceded by the
228 .Ic !\&
229 operator.
230 If a shell function is executed and its exit status is explicitly
231 tested, all commands of the function are considered to be tested as
232 well.
233 .It Fl f Li noglob
234 Disable pathname expansion.
235 .It Fl I Li ignoreeof
236 Ignore
237 .Dv EOF Ap s
238 from input when in interactive mode.
239 .It Fl i Li interactive
240 Force the shell to behave interactively.
241 .It Fl m Li monitor
242 Turn on job control (set automatically when interactive).
243 .It Fl n Li noexec
244 If not interactive, read commands but do not
245 execute them.
246 This is useful for checking the
247 syntax of shell scripts.
248 .It Fl P Li physical
249 Change the default for the
250 .Ic cd
251 and
252 .Ic pwd
253 commands from
254 .Fl L
255 (logical directory layout)
256 to
257 .Fl P
258 (physical directory layout).
259 .It Fl p Li privileged
260 Turn on privileged mode.
261 This mode is enabled on startup
262 if either the effective user or group ID is not equal to the
263 real user or group ID.
264 Turning this mode off sets the
265 effective user and group IDs to the real user and group IDs.
266 When this mode is enabled for interactive shells, the file
267 .Pa /etc/suid_profile
268 is sourced instead of
269 .Pa ~/.profile
270 after
271 .Pa /etc/profile
272 is sourced, and the contents of the
273 .Ev ENV
274 variable are ignored.
275 .It Fl s Li stdin
276 Read commands from standard input (set automatically
277 if no file arguments are present).
278 This option has
279 no effect when set after the shell has already started
280 running (i.e., when set with the
281 .Ic set
282 command).
283 .It Fl T Li trapsasync
284 When waiting for a child, execute traps immediately.
285 If this option is not set,
286 traps are executed after the child exits,
287 as specified in
288 .St -p1003.2 .
289 This nonstandard option is useful for putting guarding shells around
290 children that block signals.
291 The surrounding shell may kill the child
292 or it may just return control to the tty and leave the child alone,
293 like this:
294 .Bd -literal -offset indent
295 sh -T -c "trap 'exit 1' 2 ; some-blocking-program"
296 .Ed
297 .It Fl u Li nounset
298 Write a message to standard error when attempting
299 to expand a variable that is not set, and if the
300 shell is not interactive, exit immediately.
301 .It Fl V Li vi
302 Enable the built-in
303 .Xr vi 1
304 command line editor (disables
305 .Fl E
306 if it has been set).
307 .It Fl v Li verbose
308 The shell writes its input to standard error
309 as it is read.
310 Useful for debugging.
311 .It Fl x Li xtrace
312 Write each command
313 (preceded by the value of the
314 .Va PS4
315 variable)
316 to standard error before it is executed.
317 Useful for debugging.
318 .El
319 .Pp
320 The
321 .Fl c
322 option causes the commands to be read from the
323 .Ar string
324 operand instead of from the standard input.
325 Keep in mind that this option only accepts a single string as its
326 argument, hence multi-word strings must be quoted.
327 .Pp
328 The
329 .Fl /+o
330 option takes as its only argument the long name of an option
331 to be enabled or disabled.
332 For example, the following two invocations of
333 .Nm
334 both enable the built-in
335 .Xr emacs 1
336 command line editor:
337 .Bd -literal -offset indent
338 set -E
339 set -o emacs
340 .Ed
341 .Pp
342 If used without an argument, the
343 .Fl o
344 option displays the current option settings in a human-readable format.
345 If
346 .Cm +o
347 is used without an argument, the current option settings are output
348 in a format suitable for re-input into the shell.
349 .Ss Lexical Structure
350 The shell reads input in terms of lines from a file and breaks
351 it up into words at whitespace (blanks and tabs), and at
352 certain sequences of
353 characters called
354 .Dq operators ,
355 which are special to the shell.
356 There are two types of operators: control operators and
357 redirection operators (their meaning is discussed later).
358 The following is a list of valid operators:
359 .Bl -tag -width indent
360 .It Control operators:
361 .Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact
362 .It Li & Ta Li && Ta Li ( Ta Li ) Ta Li \en
363 .It Li ;; Ta Li ; Ta Li | Ta Li ||
364 .El
365 .It Redirection operators:
366 .Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact
367 .It Li < Ta Li > Ta Li << Ta Li >> Ta Li <>
368 .It Li <& Ta Li >& Ta Li <<- Ta Li >|
369 .El
370 .El
371 .Pp
372 The character
373 .Ql #
374 introduces a comment if used at the beginning of a word.
375 The word starting with
376 .Ql #
377 and the rest of the line are ignored.
378 .Pp
379 .Tn ASCII
380 .Dv NUL
381 characters (character code 0) are not allowed in shell input.
382 .Ss Quoting
383 Quoting is used to remove the special meaning of certain characters
384 or words to the shell, such as operators, whitespace, keywords,
385 or alias names.
386 .Pp
387 There are three types of quoting: matched single quotes,
388 matched double quotes, and backslash.
389 .Bl -tag -width indent
390 .It Single Quotes
391 Enclosing characters in single quotes preserves the literal
392 meaning of all the characters (except single quotes, making
393 it impossible to put single-quotes in a single-quoted string).
394 .It Double Quotes
395 Enclosing characters within double quotes preserves the literal
396 meaning of all characters except dollar sign
397 .Pq Ql $ ,
398 backquote
399 .Pq Ql ` ,
400 and backslash
401 .Pq Ql \e .
402 The backslash inside double quotes is historically weird.
403 It remains literal unless it precedes the following characters,
404 which it serves to quote:
405 .Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact
406 .It Li $ Ta Li ` Ta Li \&" Ta Li \e\  Ta Li \en
407 .El
408 .It Backslash
409 A backslash preserves the literal meaning of the following
410 character, with the exception of the newline character
411 .Pq Ql \en .
412 A backslash preceding a newline is treated as a line continuation.
413 .El
414 .Ss Keywords
415 Keywords or reserved words are words that have special meaning to the
416 shell and are recognized at the beginning of a line and
417 after a control operator.
418 The following are keywords:
419 .Bl -column "doneXX" "elifXX" "elseXX" "untilXX" "whileX" -offset center
420 .It Li \&! Ta { Ta } Ta Ic case Ta Ic do
421 .It Ic done Ta Ic elif Ta Ic else Ta Ic esac Ta Ic fi
422 .It Ic for Ta Ic if Ta Ic then Ta Ic until Ta Ic while
423 .El
424 .Ss Aliases
425 An alias is a name and corresponding value set using the
426 .Ic alias
427 built-in command.
428 Whenever a keyword may occur (see above),
429 and after checking for keywords, the shell
430 checks the word to see if it matches an alias.
431 If it does, it replaces it in the input stream with its value.
432 For example, if there is an alias called
433 .Dq Li lf
434 with the value
435 .Dq Li "ls -F" ,
436 then the input
437 .Pp
438 .Dl "lf foobar"
439 .Pp
440 would become
441 .Pp
442 .Dl "ls -F foobar"
443 .Pp
444 Aliases provide a convenient way for naive users to
445 create shorthands for commands without having to learn how
446 to create functions with arguments.
447 They can also be
448 used to create lexically obscure code.
449 This use is discouraged.
450 .Pp
451 An alias name may be escaped in a command line, so that it is not
452 replaced by its alias value, by using quoting characters within or
453 adjacent to the alias name.
454 This is most often done by prefixing
455 an alias name with a backslash to execute a function, built-in, or
456 normal program with the same name.
457 See the
458 .Sx Quoting
459 subsection.
460 .Ss Commands
461 The shell interprets the words it reads according to a
462 language, the specification of which is outside the scope
463 of this man page (refer to the BNF in the
464 .St -p1003.2
465 document).
466 Essentially though, a line is read and if
467 the first word of the line (or after a control operator)
468 is not a keyword, then the shell has recognized a
469 simple command.
470 Otherwise, a complex command or some
471 other special construct may have been recognized.
472 .Ss Simple Commands
473 If a simple command has been recognized, the shell performs
474 the following actions:
475 .Bl -enum
476 .It
477 Leading words of the form
478 .Dq Li name=value
479 are stripped off and assigned to the environment of
480 the simple command.
481 Redirection operators and
482 their arguments (as described below) are stripped
483 off and saved for processing.
484 .It
485 The remaining words are expanded as described in
486 the section called
487 .Sx Word Expansions ,
488 and the first remaining word is considered the command
489 name and the command is located.
490 The remaining
491 words are considered the arguments of the command.
492 If no command name resulted, then the
493 .Dq Li name=value
494 variable assignments recognized in 1) affect the
495 current shell.
496 .It
497 Redirections are performed as described in
498 the next section.
499 .El
500 .Ss Redirections
501 Redirections are used to change where a command reads its input
502 or sends its output.
503 In general, redirections open, close, or
504 duplicate an existing reference to a file.
505 The overall format
506 used for redirection is:
507 .Pp
508 .D1 Oo Ar n Oc Ar redir-op file
509 .Pp
510 The
511 .Ar redir-op
512 is one of the redirection operators mentioned
513 previously.
514 The following gives some examples of how these
515 operators can be used.
516 Note that stdin and stdout are commonly used abbreviations
517 for standard input and standard output respectively.
518 .Bl -tag -width "1234567890XX" -offset indent
519 .It Oo Ar n Oc Ns Li > Ar file
520 redirect stdout (or file descriptor
521 .Ar n )
522 to
523 .Ar file
524 .It Oo Ar n Oc Ns Li >| Ar file
525 same as above, but override the
526 .Fl C
527 option
528 .It Oo Ar n Oc Ns Li >> Ar file
529 append stdout (or file descriptor
530 .Ar n )
531 to
532 .Ar file
533 .It Oo Ar n Oc Ns Li < Ar file
534 redirect stdin (or file descriptor
535 .Ar n )
536 from
537 .Ar file
538 .It Oo Ar n Oc Ns Li <> Ar file
539 redirect stdin (or file descriptor
540 .Ar n )
541 to and from
542 .Ar file
543 .It Oo Ar n1 Oc Ns Li <& Ns Ar n2
544 duplicate stdin (or file descriptor
545 .Ar n1 )
546 from file descriptor
547 .Ar n2
548 .It Oo Ar n Oc Ns Li <&-
549 close stdin (or file descriptor
550 .Ar n )
551 .It Oo Ar n1 Oc Ns Li >& Ns Ar n2
552 duplicate stdout (or file descriptor
553 .Ar n1 )
554 to file descriptor
555 .Ar n2
556 .It Oo Ar n Oc Ns Li >&-
557 close stdout (or file descriptor
558 .Ar n )
559 .El
560 .Pp
561 The following redirection is often called a
562 .Dq here-document .
563 .Bd -unfilled -offset indent
564 .Oo Ar n Oc Ns Li << Ar delimiter
565 .D1 Ar here-doc-text
566 .D1 ...
567 .Ar delimiter
568 .Ed
569 .Pp
570 All the text on successive lines up to the delimiter is
571 saved away and made available to the command on standard
572 input, or file descriptor
573 .Ar n
574 if it is specified.
575 If the
576 .Ar delimiter
577 as specified on the initial line is quoted, then the
578 .Ar here-doc-text
579 is treated literally, otherwise the text is subjected to
580 parameter expansion, command substitution, and arithmetic
581 expansion (as described in the section on
582 .Sx Word Expansions ) .
583 If the operator is
584 .Dq Li <<-
585 instead of
586 .Dq Li << ,
587 then leading tabs
588 in the
589 .Ar here-doc-text
590 are stripped.
591 .Ss Search and Execution
592 There are three types of commands: shell functions,
593 built-in commands, and normal programs.
594 The command is searched for (by name) in that order.
595 The three types of commands are all executed in a different way.
596 .Pp
597 When a shell function is executed, all of the shell positional
598 parameters (except
599 .Li $0 ,
600 which remains unchanged) are
601 set to the arguments of the shell function.
602 The variables which are explicitly placed in the environment of
603 the command (by placing assignments to them before the
604 function name) are made local to the function and are set
605 to the values given.
606 Then the command given in the function definition is executed.
607 The positional parameters are restored to their original values
608 when the command completes.
609 This all occurs within the current shell.
610 .Pp
611 Shell built-in commands are executed internally to the shell, without
612 spawning a new process.
613 There are two kinds of built-in commands: regular and special.
614 Assignments before special builtins persist after they finish
615 executing and assignment errors, redirection errors and certain
616 operand errors cause a script to be aborted.
617 Both regular and special builtins can affect the shell in ways
618 normal programs cannot.
619 .Pp
620 Otherwise, if the command name does not match a function
621 or built-in command, the command is searched for as a normal
622 program in the file system (as described in the next section).
623 When a normal program is executed, the shell runs the program,
624 passing the arguments and the environment to the program.
625 If the program is not a normal executable file
626 (i.e., if it does not begin with the
627 .Dq "magic number"
628 whose
629 .Tn ASCII
630 representation is
631 .Dq Li #! ,
632 resulting in an
633 .Er ENOEXEC
634 return value from
635 .Xr execve 2 )
636 the shell will interpret the program in a subshell.
637 The child shell will reinitialize itself in this case,
638 so that the effect will be
639 as if a new shell had been invoked to handle the ad-hoc shell script,
640 except that the location of hashed commands located in
641 the parent shell will be remembered by the child
642 (see the description of the
643 .Ic hash
644 built-in command below).
645 .Pp
646 Note that previous versions of this document
647 and the source code itself misleadingly and sporadically
648 refer to a shell script without a magic number
649 as a
650 .Dq "shell procedure" .
651 .Ss Path Search
652 When locating a command, the shell first looks to see if
653 it has a shell function by that name.
654 Then it looks for a
655 built-in command by that name.
656 If a built-in command is not found,
657 one of two things happen:
658 .Bl -enum
659 .It
660 Command names containing a slash are simply executed without
661 performing any searches.
662 .It
663 The shell searches each entry in the
664 .Ev PATH
665 environment variable
666 in turn for the command.
667 The value of the
668 .Ev PATH
669 variable should be a series of
670 entries separated by colons.
671 Each entry consists of a
672 directory name.
673 The current directory
674 may be indicated implicitly by an empty directory name,
675 or explicitly by a single period.
676 .El
677 .Ss Command Exit Status
678 Each command has an exit status that can influence the behavior
679 of other shell commands.
680 The paradigm is that a command exits
681 with zero for normal or success, and non-zero for failure,
682 error, or a false indication.
683 The man page for each command
684 should indicate the various exit codes and what they mean.
685 Additionally, the built-in commands return exit codes, as does
686 an executed shell function.
687 .Pp
688 If a command is terminated by a signal, its exit status is 128 plus
689 the signal number.
690 Signal numbers are defined in the header file
691 .In sys/signal.h .
692 .Ss Complex Commands
693 Complex commands are combinations of simple commands
694 with control operators or keywords, together creating a larger complex
695 command.
696 More generally, a command is one of the following:
697 .Bl -item -offset indent
698 .It
699 simple command
700 .It
701 pipeline
702 .It
703 list or compound-list
704 .It
705 compound command
706 .It
707 function definition
708 .El
709 .Pp
710 Unless otherwise stated, the exit status of a command is
711 that of the last simple command executed by the command.
712 .Ss Pipelines
713 A pipeline is a sequence of one or more commands separated
714 by the control operator
715 .Ql \&| .
716 The standard output of all but
717 the last command is connected to the standard input
718 of the next command.
719 The standard output of the last
720 command is inherited from the shell, as usual.
721 .Pp
722 The format for a pipeline is:
723 .Pp
724 .D1 Oo Li \&! Oc Ar command1 Op Li \&| Ar command2 ...
725 .Pp
726 The standard output of
727 .Ar command1
728 is connected to the standard input of
729 .Ar command2 .
730 The standard input, standard output, or
731 both of a command is considered to be assigned by the
732 pipeline before any redirection specified by redirection
733 operators that are part of the command.
734 .Pp
735 If the pipeline is not in the background (discussed later),
736 the shell waits for all commands to complete.
737 .Pp
738 If the keyword
739 .Ic !\&
740 does not precede the pipeline, the
741 exit status is the exit status of the last command specified
742 in the pipeline.
743 Otherwise, the exit status is the logical
744 NOT of the exit status of the last command.
745 That is, if
746 the last command returns zero, the exit status is 1; if
747 the last command returns greater than zero, the exit status
748 is zero.
749 .Pp
750 Because pipeline assignment of standard input or standard
751 output or both takes place before redirection, it can be
752 modified by redirection.
753 For example:
754 .Pp
755 .Dl "command1 2>&1 | command2"
756 .Pp
757 sends both the standard output and standard error of
758 .Ar command1
759 to the standard input of
760 .Ar command2 .
761 .Pp
762 A
763 .Ql \&;
764 or newline terminator causes the preceding
765 AND-OR-list
766 (described below in the section called
767 .Sx Short-Circuit List Operators )
768 to be executed sequentially;
769 an
770 .Ql &
771 causes asynchronous execution of the preceding AND-OR-list.
772 .Pp
773 Note that unlike some other shells,
774 .Nm
775 executes each process in the pipeline as a child of the
776 .Nm
777 process.
778 Shell built-in commands are the exception to this rule.
779 They are executed in the current shell, although they do not affect its
780 environment when used in pipelines.
781 .Ss Background Commands (&)
782 If a command is terminated by the control operator ampersand
783 .Pq Ql & ,
784 the shell executes the command asynchronously;
785 the shell does not wait for the command to finish
786 before executing the next command.
787 .Pp
788 The format for running a command in background is:
789 .Pp
790 .D1 Ar command1 Li & Op Ar command2 Li & Ar ...
791 .Pp
792 If the shell is not interactive, the standard input of an
793 asynchronous command is set to
794 .Pa /dev/null .
795 .Ss Lists (Generally Speaking)
796 A list is a sequence of zero or more commands separated by
797 newlines, semicolons, or ampersands,
798 and optionally terminated by one of these three characters.
799 The commands in a
800 list are executed in the order they are written.
801 If command is followed by an ampersand, the shell starts the
802 command and immediately proceeds onto the next command;
803 otherwise it waits for the command to terminate before
804 proceeding to the next one.
805 .Ss Short-Circuit List Operators
806 .Dq Li &&
807 and
808 .Dq Li ||
809 are AND-OR list operators.
810 .Dq Li &&
811 executes the first command, and then executes the second command
812 if the exit status of the first command is zero.
813 .Dq Li ||
814 is similar, but executes the second command if the exit
815 status of the first command is nonzero.
816 .Dq Li &&
817 and
818 .Dq Li ||
819 both have the same priority.
820 .Ss Flow-Control Constructs (if, while, for, case)
821 The syntax of the
822 .Ic if
823 command is:
824 .Bd -unfilled -offset indent -compact
825 .Ic if Ar list
826 .Ic then Ar list
827 .Oo Ic elif Ar list
828 .Ic then Ar list Oc Ar ...
829 .Op Ic else Ar list
830 .Ic fi
831 .Ed
832 .Pp
833 The syntax of the
834 .Ic while
835 command is:
836 .Bd -unfilled -offset indent -compact
837 .Ic while Ar list
838 .Ic do Ar list
839 .Ic done
840 .Ed
841 .Pp
842 The two lists are executed repeatedly while the exit status of the
843 first list is zero.
844 The
845 .Ic until
846 command is similar, but has the word
847 .Ic until
848 in place of
849 .Ic while ,
850 which causes it to
851 repeat until the exit status of the first list is zero.
852 .Pp
853 The syntax of the
854 .Ic for
855 command is:
856 .Bd -unfilled -offset indent -compact
857 .Ic for Ar variable Op Ic in Ar word ...
858 .Ic do Ar list
859 .Ic done
860 .Ed
861 .Pp
862 If
863 .Ic in
864 and the following words are omitted,
865 .Ic in Li \&"$@\&"
866 is used instead.
867 The words are expanded, and then the list is executed
868 repeatedly with the variable set to each word in turn.
869 The
870 .Ic do
871 and
872 .Ic done
873 commands may be replaced with
874 .Ql {
875 and
876 .Ql } .
877 .Pp
878 The syntax of the
879 .Ic break
880 and
881 .Ic continue
882 commands is:
883 .D1 Ic break Op Ar num
884 .D1 Ic continue Op Ar num
885 .Pp
886 The
887 .Ic break
888 command terminates the
889 .Ar num
890 innermost
891 .Ic for
892 or
893 .Ic while
894 loops.
895 The
896 .Ic continue
897 command continues with the next iteration of the innermost loop.
898 These are implemented as special built-in commands.
899 .Pp
900 The syntax of the
901 .Ic case
902 command is:
903 .Bd -unfilled -offset indent -compact
904 .Ic case Ar word Ic in
905 .Ar pattern Ns Li ) Ar list Li ;;
906 .Ar ...
907 .Ic esac
908 .Ed
909 .Pp
910 The pattern can actually be one or more patterns
911 (see
912 .Sx Shell Patterns
913 described later),
914 separated by
915 .Ql \&|
916 characters.
917 The exit code of the
918 .Ic case
919 command is the exit code of the last command executed in the list or
920 zero if no patterns were matched.
921 .Ss Grouping Commands Together
922 Commands may be grouped by writing either
923 .Pp
924 .D1 Li \&( Ns Ar list Ns Li \%)
925 .Pp
926 or
927 .Pp
928 .D1 Li { Ar list Ns Li \&; }
929 .Pp
930 The first form executes the commands in a subshell.
931 Note that built-in commands thus executed do not affect the current shell.
932 The second form does not fork another shell,
933 so it is slightly more efficient.
934 Grouping commands together this way allows the user to
935 redirect their output as though they were one program:
936 .Bd -literal -offset indent
937 { echo -n "hello"; echo " world"; } > greeting
938 .Ed
939 .Ss Functions
940 The syntax of a function definition is
941 .Pp
942 .D1 Ar name Li \&( \&) Ar command
943 .Pp
944 A function definition is an executable statement; when
945 executed it installs a function named
946 .Ar name
947 and returns an
948 exit status of zero.
949 The
950 .Ar command
951 is normally a list
952 enclosed between
953 .Ql {
954 and
955 .Ql } .
956 .Pp
957 Variables may be declared to be local to a function by
958 using the
959 .Ic local
960 command.
961 This should appear as the first statement of a function,
962 and the syntax is:
963 .Pp
964 .D1 Ic local Oo Ar variable ... Oc Op Fl
965 .Pp
966 The
967 .Ic local
968 command is implemented as a built-in command.
969 .Pp
970 When a variable is made local, it inherits the initial
971 value and exported and readonly flags from the variable
972 with the same name in the surrounding scope, if there is
973 one.
974 Otherwise, the variable is initially unset.
975 The shell
976 uses dynamic scoping, so that if the variable
977 .Va x
978 is made local to function
979 .Em f ,
980 which then calls function
981 .Em g ,
982 references to the variable
983 .Va x
984 made inside
985 .Em g
986 will refer to the variable
987 .Va x
988 declared inside
989 .Em f ,
990 not to the global variable named
991 .Va x .
992 .Pp
993 The only special parameter that can be made local is
994 .Ql - .
995 Making
996 .Ql -
997 local causes any shell options that are
998 changed via the
999 .Ic set
1000 command inside the function to be
1001 restored to their original values when the function
1002 returns.
1003 .Pp
1004 The syntax of the
1005 .Ic return
1006 command is
1007 .Pp
1008 .D1 Ic return Op Ar exitstatus
1009 .Pp
1010 It terminates the current executional scope, returning from the previous
1011 nested function, sourced script, or shell instance, in that order.
1012 The
1013 .Ic return
1014 command is implemented as a special built-in command.
1015 .Ss Variables and Parameters
1016 The shell maintains a set of parameters.
1017 A parameter
1018 denoted by a name is called a variable.
1019 When starting up,
1020 the shell turns all the environment variables into shell
1021 variables.
1022 New variables can be set using the form
1023 .Pp
1024 .D1 Ar name Ns = Ns Ar value
1025 .Pp
1026 Variables set by the user must have a name consisting solely
1027 of alphabetics, numerics, and underscores.
1028 The first letter of a variable name must not be numeric.
1029 A parameter can also be denoted by a number
1030 or a special character as explained below.
1031 .Ss Positional Parameters
1032 A positional parameter is a parameter denoted by a number greater than zero.
1033 The shell sets these initially to the values of its command line
1034 arguments that follow the name of the shell script.
1035 The
1036 .Ic set
1037 built-in command can also be used to set or reset them.
1038 .Ss Special Parameters
1039 A special parameter is a parameter denoted by a special one-character
1040 name.
1041 The special parameters recognized by the
1042 .Nm
1043 shell of
1044 .Fx
1045 are shown in the following list, exactly as they would appear in input
1046 typed by the user or in the source of a shell script.
1047 .Bl -hang
1048 .It Li $*
1049 Expands to the positional parameters, starting from one.
1050 When
1051 the expansion occurs within a double-quoted string
1052 it expands to a single field with the value of each parameter
1053 separated by the first character of the
1054 .Va IFS
1055 variable,
1056 or by a space if
1057 .Va IFS
1058 is unset.
1059 .It Li $@
1060 Expands to the positional parameters, starting from one.
1061 When
1062 the expansion occurs within double-quotes, each positional
1063 parameter expands as a separate argument.
1064 If there are no positional parameters, the
1065 expansion of
1066 .Li @
1067 generates zero arguments, even when
1068 .Li @
1069 is double-quoted.
1070 What this basically means, for example, is
1071 if
1072 .Li $1
1073 is
1074 .Dq Li abc
1075 and
1076 .Li $2
1077 is
1078 .Dq Li "def ghi" ,
1079 then
1080 .Li \&"$@\&"
1081 expands to
1082 the two arguments:
1083 .Bd -literal -offset indent
1084 "abc"   "def ghi"
1085 .Ed
1086 .It Li $#
1087 Expands to the number of positional parameters.
1088 .It Li $?
1089 Expands to the exit status of the most recent pipeline.
1090 .It Li $-
1091 (hyphen) Expands to the current option flags (the single-letter
1092 option names concatenated into a string) as specified on
1093 invocation, by the
1094 .Ic set
1095 built-in command, or implicitly
1096 by the shell.
1097 .It Li $$
1098 Expands to the process ID of the invoked shell.
1099 A subshell
1100 retains the same value of
1101 .Va $
1102 as its parent.
1103 .It Li $!
1104 Expands to the process ID of the most recent background
1105 command executed from the current shell.
1106 For a
1107 pipeline, the process ID is that of the last command in the
1108 pipeline.
1109 .It Li $0
1110 (zero) Expands to the name of the shell or shell script.
1111 .El
1112 .Ss Word Expansions
1113 This clause describes the various expansions that are
1114 performed on words.
1115 Not all expansions are performed on
1116 every word, as explained later.
1117 .Pp
1118 Tilde expansions, parameter expansions, command substitutions,
1119 arithmetic expansions, and quote removals that occur within
1120 a single word expand to a single field.
1121 It is only field
1122 splitting or pathname expansion that can create multiple
1123 fields from a single word.
1124 The single exception to this rule is
1125 the expansion of the special parameter
1126 .Va @
1127 within double-quotes,
1128 as was described above.
1129 .Pp
1130 The order of word expansion is:
1131 .Bl -enum
1132 .It
1133 Tilde Expansion, Parameter Expansion, Command Substitution,
1134 Arithmetic Expansion (these all occur at the same time).
1135 .It
1136 Field Splitting is performed on fields generated by step (1)
1137 unless the
1138 .Va IFS
1139 variable is null.
1140 .It
1141 Pathname Expansion (unless the
1142 .Fl f
1143 option is in effect).
1144 .It
1145 Quote Removal.
1146 .El
1147 .Pp
1148 The
1149 .Ql $
1150 character is used to introduce parameter expansion, command
1151 substitution, or arithmetic expansion.
1152 .Ss Tilde Expansion (substituting a user's home directory)
1153 A word beginning with an unquoted tilde character
1154 .Pq Ql ~
1155 is
1156 subjected to tilde expansion.
1157 All the characters up to a slash
1158 .Pq Ql /
1159 or the end of the word are treated as a username
1160 and are replaced with the user's home directory.
1161 If the
1162 username is missing (as in
1163 .Pa ~/foobar ) ,
1164 the tilde is replaced with the value of the
1165 .Ev HOME
1166 variable (the current user's home directory).
1167 .Ss Parameter Expansion
1168 The format for parameter expansion is as follows:
1169 .Pp
1170 .D1 Li ${ Ns Ar expression Ns Li }
1171 .Pp
1172 where
1173 .Ar expression
1174 consists of all characters until the matching
1175 .Ql } .
1176 Any
1177 .Ql }
1178 escaped by a backslash or within a quoted string, and characters in
1179 embedded arithmetic expansions, command substitutions, and variable
1180 expansions, are not examined in determining the matching
1181 .Ql } .
1182 .Pp
1183 The simplest form for parameter expansion is:
1184 .Pp
1185 .D1 Li ${ Ns Ar parameter Ns Li }
1186 .Pp
1187 The value, if any, of
1188 .Ar parameter
1189 is substituted.
1190 .Pp
1191 The parameter name or symbol can be enclosed in braces, which are
1192 optional except for positional parameters with more than one digit or
1193 when parameter is followed by a character that could be interpreted as
1194 part of the name.
1195 If a parameter expansion occurs inside double-quotes:
1196 .Bl -enum
1197 .It
1198 Pathname expansion is not performed on the results of the
1199 expansion.
1200 .It
1201 Field splitting is not performed on the results of the
1202 expansion, with the exception of the special parameter
1203 .Va @ .
1204 .El
1205 .Pp
1206 In addition, a parameter expansion can be modified by using one of the
1207 following formats.
1208 .Bl -tag -width indent
1209 .It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li }
1210 Use Default Values.
1211 If
1212 .Ar parameter
1213 is unset or null, the expansion of
1214 .Ar word
1215 is substituted; otherwise, the value of
1216 .Ar parameter
1217 is substituted.
1218 .It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li }
1219 Assign Default Values.
1220 If
1221 .Ar parameter
1222 is unset or null, the expansion of
1223 .Ar word
1224 is assigned to
1225 .Ar parameter .
1226 In all cases, the
1227 final value of
1228 .Ar parameter
1229 is substituted.
1230 Quoting inside
1231 .Ar word
1232 does not prevent field splitting or pathname expansion.
1233 Only variables, not positional
1234 parameters or special parameters, can be
1235 assigned in this way.
1236 .It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li }
1237 Indicate Error if Null or Unset.
1238 If
1239 .Ar parameter
1240 is unset or null, the expansion of
1241 .Ar word
1242 (or a message indicating it is unset if
1243 .Ar word
1244 is omitted) is written to standard
1245 error and the shell exits with a nonzero
1246 exit status.
1247 Otherwise, the value of
1248 .Ar parameter
1249 is substituted.
1250 An
1251 interactive shell need not exit.
1252 .It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li }
1253 Use Alternate Value.
1254 If
1255 .Ar parameter
1256 is unset or null, null is substituted;
1257 otherwise, the expansion of
1258 .Ar word
1259 is substituted.
1260 .El
1261 .Pp
1262 In the parameter expansions shown previously, use of the colon in the
1263 format results in a test for a parameter that is unset or null; omission
1264 of the colon results in a test for a parameter that is only unset.
1265 .Bl -tag -width indent
1266 .It Li ${# Ns Ar parameter Ns Li }
1267 String Length.
1268 The length in characters of
1269 the value of
1270 .Ar parameter .
1271 .El
1272 .Pp
1273 The following four varieties of parameter expansion provide for substring
1274 processing.
1275 In each case, pattern matching notation
1276 (see
1277 .Sx Shell Patterns ) ,
1278 rather than regular expression notation,
1279 is used to evaluate the patterns.
1280 If parameter is one of the special parameters
1281 .Va *
1282 or
1283 .Va @ ,
1284 the result of the expansion is unspecified.
1285 Enclosing the full parameter expansion string in double-quotes does not
1286 cause the following four varieties of pattern characters to be quoted,
1287 whereas quoting characters within the braces has this effect.
1288 .Bl -tag -width indent
1289 .It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li }
1290 Remove Smallest Suffix Pattern.
1291 The
1292 .Ar word
1293 is expanded to produce a pattern.
1294 The
1295 parameter expansion then results in
1296 .Ar parameter ,
1297 with the smallest portion of the
1298 suffix matched by the pattern deleted.
1299 .It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li }
1300 Remove Largest Suffix Pattern.
1301 The
1302 .Ar word
1303 is expanded to produce a pattern.
1304 The
1305 parameter expansion then results in
1306 .Ar parameter ,
1307 with the largest portion of the
1308 suffix matched by the pattern deleted.
1309 .It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li }
1310 Remove Smallest Prefix Pattern.
1311 The
1312 .Ar word
1313 is expanded to produce a pattern.
1314 The
1315 parameter expansion then results in
1316 .Ar parameter ,
1317 with the smallest portion of the
1318 prefix matched by the pattern deleted.
1319 .It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li }
1320 Remove Largest Prefix Pattern.
1321 The
1322 .Ar word
1323 is expanded to produce a pattern.
1324 The
1325 parameter expansion then results in
1326 .Ar parameter ,
1327 with the largest portion of the
1328 prefix matched by the pattern deleted.
1329 .El
1330 .Ss Command Substitution
1331 Command substitution allows the output of a command to be substituted in
1332 place of the command name itself.
1333 Command substitution occurs when
1334 the command is enclosed as follows:
1335 .Pp
1336 .D1 Li $( Ns Ar command Ns Li )\&
1337 .Pp
1338 or the backquoted version:
1339 .Pp
1340 .D1 Li ` Ns Ar command Ns Li `
1341 .Pp
1342 The shell expands the command substitution by executing command in a
1343 subshell environment and replacing the command substitution
1344 with the standard output of the command,
1345 removing sequences of one or more newlines at the end of the substitution.
1346 Embedded newlines before the end of the output are not removed;
1347 however, during field splitting, they may be translated into spaces
1348 depending on the value of
1349 .Va IFS
1350 and the quoting that is in effect.
1351 .Ss Arithmetic Expansion
1352 Arithmetic expansion provides a mechanism for evaluating an arithmetic
1353 expression and substituting its value.
1354 The format for arithmetic expansion is as follows:
1355 .Pp
1356 .D1 Li $(( Ns Ar expression Ns Li ))
1357 .Pp
1358 The
1359 .Ar expression
1360 is treated as if it were in double-quotes, except
1361 that a double-quote inside the expression is not treated specially.
1362 The
1363 shell expands all tokens in the
1364 .Ar expression
1365 for parameter expansion,
1366 command substitution,
1367 arithmetic expansion
1368 and quote removal.
1369 .Pp
1370 The allowed expressions are a subset of C expressions,
1371 summarized below.
1372 .Bl -tag -width "Variables" -offset indent
1373 .It Values
1374 All values are of type
1375 .Ft intmax_t .
1376 .It Constants
1377 Decimal, octal (starting with
1378 .Li 0 )
1379 and hexadecimal (starting with 
1380 .Li 0x )
1381 integer constants.
1382 .It Variables
1383 Shell variables can be read and written
1384 and contain integer constants.
1385 .It Unary operators
1386 .Li "! ~ + -"
1387 .It Binary operators
1388 .Li "* / % + - << >> < <= > >= == != & ^ | && ||"
1389 .It Assignment operators
1390 .Li "= += -= *= /= %= <<= >>= &= ^= |="
1391 .It Short-circuit evaluation
1392 The
1393 .Li &&
1394 and
1395 .Li ||
1396 operators always evaluate both sides.
1397 This is a bug.
1398 .El
1399 .Pp
1400 The result of the expression is substituted in decimal.
1401 .Ss White Space Splitting (Field Splitting)
1402 After parameter expansion, command substitution, and
1403 arithmetic expansion the shell scans the results of
1404 expansions and substitutions that did not occur in double-quotes for
1405 field splitting and multiple fields can result.
1406 .Pp
1407 The shell treats each character of the
1408 .Va IFS
1409 variable as a delimiter and uses
1410 the delimiters to split the results of parameter expansion and command
1411 substitution into fields.
1412 .Ss Pathname Expansion (File Name Generation)
1413 Unless the
1414 .Fl f
1415 option is set,
1416 file name generation is performed
1417 after word splitting is complete.
1418 Each word is
1419 viewed as a series of patterns, separated by slashes.
1420 The
1421 process of expansion replaces the word with the names of
1422 all existing files whose names can be formed by replacing
1423 each pattern with a string that matches the specified pattern.
1424 There are two restrictions on this: first, a pattern cannot match
1425 a string containing a slash, and second,
1426 a pattern cannot match a string starting with a period
1427 unless the first character of the pattern is a period.
1428 The next section describes the patterns used for both
1429 Pathname Expansion and the
1430 .Ic case
1431 command.
1432 .Ss Shell Patterns
1433 A pattern consists of normal characters, which match themselves,
1434 and meta-characters.
1435 The meta-characters are
1436 .Ql \&! ,
1437 .Ql * ,
1438 .Ql \&? ,
1439 and
1440 .Ql \&[ .
1441 These characters lose their special meanings if they are quoted.
1442 When command or variable substitution is performed and the dollar sign
1443 or back quotes are not double-quoted, the value of the
1444 variable or the output of the command is scanned for these
1445 characters and they are turned into meta-characters.
1446 .Pp
1447 An asterisk
1448 .Pq Ql *
1449 matches any string of characters.
1450 A question mark
1451 .Pq Ql \&?
1452 matches any single character.
1453 A left bracket
1454 .Pq Ql \&[
1455 introduces a character class.
1456 The end of the character class is indicated by a
1457 .Ql \&] ;
1458 if the
1459 .Ql \&]
1460 is missing then the
1461 .Ql \&[
1462 matches a
1463 .Ql \&[
1464 rather than introducing a character class.
1465 A character class matches any of the characters between the square brackets.
1466 A range of characters may be specified using a minus sign.
1467 The character class may be complemented by making an exclamation point
1468 .Pq Ql !\&
1469 the first character of the character class.
1470 .Pp
1471 To include a
1472 .Ql \&]
1473 in a character class, make it the first character listed
1474 (after the
1475 .Ql \&! ,
1476 if any).
1477 To include a
1478 .Ql - ,
1479 make it the first or last character listed.
1480 .Ss Built-in Commands
1481 This section lists the commands which
1482 are built-in because they need to perform some operation
1483 that cannot be performed by a separate process.
1484 In addition to
1485 these, built-in versions of essential utilities
1486 are provided for efficiency.
1487 .Bl -tag -width indent
1488 .It Ic \&:
1489 A null command that returns a 0 (true) exit value.
1490 .It Ic \&. Ar file
1491 The commands in the specified file are read and executed by the shell.
1492 The
1493 .Ic return
1494 command may be used to return to the
1495 .Ic \&.
1496 command's caller.
1497 If
1498 .Ar file
1499 contains any
1500 .Ql /
1501 characters, it is used as is.
1502 Otherwise, the shell searches the
1503 .Ev PATH
1504 for the file.
1505 If it is not found in the
1506 .Ev PATH ,
1507 it is sought in the current working directory.
1508 .It Ic \&[
1509 A built-in equivalent of
1510 .Xr test 1 .
1511 .It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc
1512 If
1513 .Ar name Ns = Ns Ar string
1514 is specified, the shell defines the alias
1515 .Ar name
1516 with value
1517 .Ar string .
1518 If just
1519 .Ar name
1520 is specified, the value of the alias
1521 .Ar name
1522 is printed.
1523 With no arguments, the
1524 .Ic alias
1525 built-in command prints the names and values of all defined aliases
1526 (see
1527 .Ic unalias ) .
1528 Alias values are written with appropriate quoting so that they are
1529 suitable for re-input to the shell.
1530 Also see the
1531 .Sx Aliases
1532 subsection.
1533 .It Ic bg Op Ar job ...
1534 Continue the specified jobs
1535 (or the current job if no jobs are given)
1536 in the background.
1537 .It Ic builtin Ar cmd Op Ar arg ...
1538 Execute the specified built-in command,
1539 .Ar cmd .
1540 This is useful when the user wishes to override a shell function
1541 with the same name as a built-in command.
1542 .It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc
1543 List or alter key bindings for the line editor.
1544 This command is documented in
1545 .Xr editrc 5 .
1546 .It Ic cd Oo Fl L | P Oc Op Ar directory
1547 Switch to the specified
1548 .Ar directory ,
1549 or to the directory specified in the
1550 .Ev HOME
1551 environment variable if no
1552 .Ar directory
1553 is specified.
1554 If
1555 .Ar directory
1556 does not begin with
1557 .Pa / , \&. ,
1558 or
1559 .Pa .. ,
1560 then the directories listed in the
1561 .Ev CDPATH
1562 variable will be
1563 searched for the specified
1564 .Ar directory .
1565 If
1566 .Ev CDPATH
1567 is unset, the current directory is searched.
1568 The format of
1569 .Ev CDPATH
1570 is the same as that of
1571 .Ev PATH .
1572 In an interactive shell,
1573 the
1574 .Ic cd
1575 command will print out the name of the directory
1576 that it actually switched to
1577 if this is different from the name that the user gave.
1578 These may be different either because the
1579 .Ev CDPATH
1580 mechanism was used or because a symbolic link was crossed.
1581 .Pp
1582 If the
1583 .Fl P
1584 option is specified,
1585 .Pa ..
1586 is handled physically and symbolic links are resolved before
1587 .Pa ..
1588 components are processed.
1589 If the
1590 .Fl L
1591 option is specified,
1592 .Pa ..
1593 is handled logically.
1594 This is the default.
1595 .It Ic chdir
1596 A synonym for the
1597 .Ic cd
1598 built-in command.
1599 .It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ...
1600 .It Ic command Oo Fl v | V Oc Op Ar utility
1601 The first form of invocation executes the specified
1602 .Ar utility
1603 as a simple command (see the
1604 .Sx Simple Commands
1605 section).
1606 .Pp
1607 If the
1608 .Fl p
1609 option is specified, the command search is performed using a
1610 default value of
1611 .Ev PATH
1612 that is guaranteed to find all of the standard utilities.
1613 .Pp
1614 If the
1615 .Fl v
1616 option is specified,
1617 .Ar utility
1618 is not executed but a description of its interpretation by the shell is
1619 printed.
1620 For ordinary commands the output is the path name; for shell built-in
1621 commands, shell functions and keywords only the name is written.
1622 Aliases are printed as
1623 .Dq Ic alias Ar name Ns = Ns Ar value .
1624 .Pp
1625 The
1626 .Fl V
1627 option is identical to
1628 .Fl v
1629 except for the output.
1630 It prints
1631 .Dq Ar utility Ic is Ar description
1632 where
1633 .Ar description
1634 is either
1635 the path name to
1636 .Ar utility ,
1637 a special shell builtin,
1638 a shell builtin,
1639 a shell function,
1640 a shell keyword
1641 or
1642 an alias for
1643 .Ar value .
1644 .It Ic echo Oo Fl e | n Oc Op Ar string ...
1645 Print a space-separated list of the arguments to the standard output
1646 and append a newline character.
1647 .Bl -tag -width indent
1648 .It Fl n
1649 Suppress the output of the trailing newline.
1650 .It Fl e
1651 Process C-style backslash escape sequences.
1652 The
1653 .Ic echo
1654 command understands the following character escapes:
1655 .Bl -tag -width indent
1656 .It \ea
1657 Alert (ring the terminal bell)
1658 .It \eb
1659 Backspace
1660 .It \ec
1661 Suppress the trailing newline (this has the side-effect of truncating the
1662 line if it is not the last character)
1663 .It \ee
1664 The ESC character
1665 .Tn ( ASCII
1666 0x1b)
1667 .It \ef
1668 Formfeed
1669 .It \en
1670 Newline
1671 .It \er
1672 Carriage return
1673 .It \et
1674 Horizontal tab
1675 .It \ev
1676 Vertical tab
1677 .It \e\e
1678 Literal backslash
1679 .It \e0nnn
1680 (Zero) The character whose octal value is
1681 .Ar nnn
1682 .El
1683 .Pp
1684 If
1685 .Ar string
1686 is not enclosed in quotes then the backslash itself must be escaped
1687 with a backslash to protect it from the shell.
1688 For example
1689 .Bd -literal -offset indent
1690 $ echo -e "a\evb"
1691 a
1692  b
1693 $ echo -e a\e\evb
1694 a
1695  b
1696 $ echo -e "a\e\eb"
1697 a\eb
1698 $ echo -e a\e\e\e\eb
1699 a\eb
1700 .Ed
1701 .El
1702 .Pp
1703 Only one of the
1704 .Fl e
1705 and
1706 .Fl n
1707 options may be specified.
1708 .It Ic eval Ar string ...
1709 Concatenate all the arguments with spaces.
1710 Then re-parse and execute the command.
1711 .It Ic exec Op Ar command Op arg ...
1712 Unless
1713 .Ar command
1714 is omitted,
1715 the shell process is replaced with the specified program
1716 (which must be a real program, not a shell built-in command or function).
1717 Any redirections on the
1718 .Ic exec
1719 command are marked as permanent,
1720 so that they are not undone when the
1721 .Ic exec
1722 command finishes.
1723 .It Ic exit Op Ar exitstatus
1724 Terminate the shell process.
1725 If
1726 .Ar exitstatus
1727 is given
1728 it is used as the exit status of the shell;
1729 otherwise the exit status of the preceding command is used.
1730 The exit status should be an integer between 0 and 255.
1731 .It Ic export Ar name ...
1732 .It Ic export Op Fl p
1733 The specified names are exported so that they will
1734 appear in the environment of subsequent commands.
1735 The only way to un-export a variable is to
1736 .Ic unset
1737 it.
1738 The shell allows the value of a variable to be set
1739 at the same time as it is exported by writing
1740 .Pp
1741 .D1 Ic export Ar name Ns = Ns Ar value
1742 .Pp
1743 With no arguments the
1744 .Ic export
1745 command lists the names
1746 of all exported variables.
1747 If the
1748 .Fl p
1749 option is specified, the exported variables are printed as
1750 .Dq Ic export Ar name Ns = Ns Ar value
1751 lines, suitable for re-input to the shell.
1752 .It Ic false
1753 A null command that returns a non-zero (false) exit value.
1754 .It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last
1755 .It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last
1756 .It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first
1757 The
1758 .Ic fc
1759 built-in command lists, or edits and re-executes,
1760 commands previously entered to an interactive shell.
1761 .Bl -tag -width indent
1762 .It Fl e Ar editor
1763 Use the editor named by
1764 .Ar editor
1765 to edit the commands.
1766 The
1767 .Ar editor
1768 string is a command name,
1769 subject to search via the
1770 .Ev PATH
1771 variable.
1772 The value in the
1773 .Ev FCEDIT
1774 variable is used as a default when
1775 .Fl e
1776 is not specified.
1777 If
1778 .Ev FCEDIT
1779 is null or unset, the value of the
1780 .Ev EDITOR
1781 variable is used.
1782 If
1783 .Ev EDITOR
1784 is null or unset,
1785 .Xr ed 1
1786 is used as the editor.
1787 .It Fl l No (ell)
1788 List the commands rather than invoking
1789 an editor on them.
1790 The commands are written in the
1791 sequence indicated by the
1792 .Ar first
1793 and
1794 .Ar last
1795 operands, as affected by
1796 .Fl r ,
1797 with each command preceded by the command number.
1798 .It Fl n
1799 Suppress command numbers when listing with
1800 .Fl l .
1801 .It Fl r
1802 Reverse the order of the commands listed
1803 (with
1804 .Fl l )
1805 or edited
1806 (with neither
1807 .Fl l
1808 nor
1809 .Fl s ) .
1810 .It Fl s
1811 Re-execute the command without invoking an editor.
1812 .It Ar first
1813 .It Ar last
1814 Select the commands to list or edit.
1815 The number of previous commands that can be accessed
1816 are determined by the value of the
1817 .Ev HISTSIZE
1818 variable.
1819 The value of
1820 .Ar first
1821 or
1822 .Ar last
1823 or both are one of the following:
1824 .Bl -tag -width indent
1825 .It Oo Cm + Oc Ns Ar num
1826 A positive number representing a command number;
1827 command numbers can be displayed with the
1828 .Fl l
1829 option.
1830 .It Fl Ar num
1831 A negative decimal number representing the
1832 command that was executed
1833 .Ar num
1834 of
1835 commands previously.
1836 For example, \-1 is the immediately previous command.
1837 .It Ar string
1838 A string indicating the most recently entered command
1839 that begins with that string.
1840 If the
1841 .Ar old Ns = Ns Ar new
1842 operand is not also specified with
1843 .Fl s ,
1844 the string form of the first operand cannot contain an embedded equal sign.
1845 .El
1846 .El
1847 .Pp
1848 The following environment variables affect the execution of
1849 .Ic fc :
1850 .Bl -tag -width ".Ev HISTSIZE"
1851 .It Ev FCEDIT
1852 Name of the editor to use for history editing.
1853 .It Ev HISTSIZE
1854 The number of previous commands that are accessible.
1855 .El
1856 .It Ic fg Op Ar job
1857 Move the specified
1858 .Ar job
1859 or the current job to the foreground.
1860 .It Ic getopts Ar optstring var
1861 The
1862 .Tn POSIX
1863 .Ic getopts
1864 command.
1865 The
1866 .Ic getopts
1867 command deprecates the older
1868 .Xr getopt 1
1869 command.
1870 The first argument should be a series of letters, each possibly
1871 followed by a colon which indicates that the option takes an argument.
1872 The specified variable is set to the parsed option.
1873 The index of
1874 the next argument is placed into the shell variable
1875 .Va OPTIND .
1876 If an option takes an argument, it is placed into the shell variable
1877 .Va OPTARG .
1878 If an invalid option is encountered,
1879 .Ar var
1880 is set to
1881 .Ql \&? .
1882 It returns a false value (1) when it encounters the end of the options.
1883 .It Ic hash Oo Fl rv Oc Op Ar command ...
1884 The shell maintains a hash table which remembers the locations of commands.
1885 With no arguments whatsoever, the
1886 .Ic hash
1887 command prints out the contents of this table.
1888 Entries which have not been looked at since the last
1889 .Ic cd
1890 command are marked with an asterisk;
1891 it is possible for these entries to be invalid.
1892 .Pp
1893 With arguments, the
1894 .Ic hash
1895 command removes each specified
1896 .Ar command
1897 from the hash table (unless they are functions) and then locates it.
1898 With the
1899 .Fl v
1900 option,
1901 .Ic hash
1902 prints the locations of the commands as it finds them.
1903 The
1904 .Fl r
1905 option causes the
1906 .Ic hash
1907 command to delete all the entries in the hash table except for functions.
1908 .It Ic jobid Op Ar job
1909 Print the process IDs of the processes in the specified
1910 .Ar job .
1911 If the
1912 .Ar job
1913 argument is omitted, use the current job.
1914 .It Ic jobs Oo Fl lps Oc Op Ar job ...
1915 Print information about the specified jobs, or all jobs if no
1916 .Ar job
1917 argument is given.
1918 The information printed includes job ID, status and command name.
1919 .Pp
1920 If the
1921 .Fl l
1922 option is specified, the PID of each job is also printed.
1923 If the
1924 .Fl p
1925 option is specified, only the process IDs for the process group leaders
1926 are printed, one per line.
1927 If the
1928 .Fl s
1929 option is specified, only the PIDs of the job commands are printed, one per
1930 line.
1931 .It Ic local Oo Ar variable ... Oc Op Fl
1932 See the
1933 .Sx Functions
1934 subsection.
1935 .It Ic pwd Op Fl L | P
1936 Print the path of the current directory.
1937 The built-in command may
1938 differ from the program of the same name because the
1939 built-in command remembers what the current directory
1940 is rather than recomputing it each time.
1941 This makes
1942 it faster.
1943 However, if the current directory is
1944 renamed,
1945 the built-in version of
1946 .Xr pwd 1
1947 will continue to print the old name for the directory.
1948 .Pp
1949 If the
1950 .Fl P
1951 option is specified, symbolic links are resolved.
1952 If the
1953 .Fl L
1954 option is specified, the shell's notion of the current directory
1955 is printed (symbolic links are not resolved).
1956 This is the default.
1957 .It Ic read Oo Fl p Ar prompt Oc Oo
1958 .Fl t Ar timeout Oc Oo Fl er Oc Ar variable ...
1959 The
1960 .Ar prompt
1961 is printed if the
1962 .Fl p
1963 option is specified
1964 and the standard input is a terminal.
1965 Then a line is
1966 read from the standard input.
1967 The trailing newline
1968 is deleted from the line and the line is split as
1969 described in the section on
1970 .Sx White Space Splitting (Field Splitting)
1971 above, and
1972 the pieces are assigned to the variables in order.
1973 If there are more pieces than variables, the remaining
1974 pieces (along with the characters in
1975 .Va IFS
1976 that separated them)
1977 are assigned to the last variable.
1978 If there are more variables than pieces, the remaining
1979 variables are assigned the null string.
1980 .Pp
1981 Backslashes are treated specially, unless the
1982 .Fl r
1983 option is
1984 specified.
1985 If a backslash is followed by
1986 a newline, the backslash and the newline will be
1987 deleted.
1988 If a backslash is followed by any other
1989 character, the backslash will be deleted and the following
1990 character will be treated as though it were not in
1991 .Va IFS ,
1992 even if it is.
1993 .Pp
1994 If the
1995 .Fl t
1996 option is specified and the
1997 .Ar timeout
1998 elapses before a complete line of input is supplied,
1999 the
2000 .Ic read
2001 command will return an exit status of 1 without assigning any values.
2002 The
2003 .Ar timeout
2004 value may optionally be followed by one of
2005 .Ql s ,
2006 .Ql m
2007 or
2008 .Ql h
2009 to explicitly specify seconds, minutes or hours.
2010 If none is supplied,
2011 .Ql s
2012 is assumed.
2013 .Pp
2014 The
2015 .Fl e
2016 option exists only for backward compatibility with older scripts.
2017 .It Ic readonly Oo Fl p Oc Op Ar name ...
2018 Each specified
2019 .Ar name
2020 is marked as read only,
2021 so that it cannot be subsequently modified or unset.
2022 The shell allows the value of a variable to be set
2023 at the same time as it is marked read only
2024 by using the following form:
2025 .Pp
2026 .D1 Ic readonly Ar name Ns = Ns Ar value
2027 .Pp
2028 With no arguments the
2029 .Ic readonly
2030 command lists the names of all read only variables.
2031 If the
2032 .Fl p
2033 option is specified, the read-only variables are printed as
2034 .Dq Ic readonly Ar name Ns = Ns Ar value
2035 lines, suitable for re-input to the shell.
2036 .It Ic return Op Ar exitstatus
2037 See the
2038 .Sx Functions
2039 subsection.
2040 .It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo
2041 .Fl c Ar string Oc Op Fl - Ar arg ...
2042 The
2043 .Ic set
2044 command performs three different functions:
2045 .Bl -item
2046 .It
2047 With no arguments, it lists the values of all shell variables.
2048 .It
2049 If options are given,
2050 either in short form or using the long
2051 .Dq Fl /+o Ar longname
2052 form,
2053 it sets or clears the specified options as described in the section called
2054 .Sx Argument List Processing .
2055 .It
2056 If the
2057 .Dq Fl -
2058 option is specified,
2059 .Ic set
2060 will replace the shell's positional parameters with the subsequent
2061 arguments.
2062 If no arguments follow the
2063 .Dq Fl -
2064 option,
2065 all the positional parameters will be cleared,
2066 which is equivalent to executing the command
2067 .Dq Li "shift $#" .
2068 The
2069 .Dq Fl -
2070 flag may be omitted when specifying arguments to be used
2071 as positional replacement parameters.
2072 This is not recommended,
2073 because the first argument may begin with a dash
2074 .Pq Ql -
2075 or a plus
2076 .Pq Ql + ,
2077 which the
2078 .Ic set
2079 command will interpret as a request to enable or disable options.
2080 .El
2081 .It Ic setvar Ar variable value
2082 Assigns the specified
2083 .Ar value
2084 to the specified
2085 .Ar variable .
2086 The
2087 .Ic setvar
2088 command is intended to be used in functions that
2089 assign values to variables whose names are passed as parameters.
2090 In general it is better to write
2091 .Dq Ar variable Ns = Ns Ar value
2092 rather than using
2093 .Ic setvar .
2094 .It Ic shift Op Ar n
2095 Shift the positional parameters
2096 .Ar n
2097 times, or once if
2098 .Ar n
2099 is not specified.
2100 A shift sets the value of
2101 .Li $1
2102 to the value of
2103 .Li $2 ,
2104 the value of
2105 .Li $2
2106 to the value of
2107 .Li $3 ,
2108 and so on,
2109 decreasing the value of
2110 .Li $#
2111 by one.
2112 If there are zero positional parameters, shifting does not do anything.
2113 .It Ic test
2114 A built-in equivalent of
2115 .Xr test 1 .
2116 .It Ic times
2117 Print the amount of time spent executing the shell and its children.
2118 The first output line shows the user and system times for the shell
2119 itself, the second one contains the user and system times for the
2120 children.
2121 .It Ic trap Oo Ar action Oc Ar signal ...
2122 .It Ic trap Fl l
2123 Cause the shell to parse and execute
2124 .Ar action
2125 when any specified
2126 .Ar signal
2127 is received.
2128 The signals are specified by name or number.
2129 In addition, the pseudo-signal
2130 .Cm EXIT
2131 may be used to specify an
2132 .Ar action
2133 that is performed when the shell terminates.
2134 The
2135 .Ar action
2136 may be an empty string or a dash
2137 .Pq Ql - ;
2138 the former causes the specified signal to be ignored
2139 and the latter causes the default action to be taken.
2140 Omitting the
2141 .Ar action
2142 is another way to request the default action, for compatibility reasons this
2143 usage is not recommended though.
2144 When the shell forks off a subshell,
2145 it resets trapped (but not ignored) signals to the default action.
2146 The
2147 .Ic trap
2148 command has no effect on signals that were ignored on entry to the shell.
2149 .Pp
2150 Option
2151 .Fl l
2152 causes the
2153 .Ic trap
2154 command to display a list of valid signal names.
2155 .It Ic true
2156 A null command that returns a 0 (true) exit value.
2157 .It Ic type Op Ar name ...
2158 Interpret each
2159 .Ar name
2160 as a command and print the resolution of the command search.
2161 Possible resolutions are:
2162 shell keyword, alias, special shell builtin, shell builtin, command,
2163 tracked alias
2164 and not found.
2165 For aliases the alias expansion is printed;
2166 for commands and tracked aliases
2167 the complete pathname of the command is printed.
2168 .It Ic ulimit Oo Fl HSabcdflmnpstuvw Oc Op Ar limit
2169 Set or display resource limits (see
2170 .Xr getrlimit 2 ) .
2171 If
2172 .Ar limit
2173 is specified, the named resource will be set;
2174 otherwise the current resource value will be displayed.
2175 .Pp
2176 If
2177 .Fl H
2178 is specified, the hard limits will be set or displayed.
2179 While everybody is allowed to reduce a hard limit,
2180 only the superuser can increase it.
2181 The
2182 .Fl S
2183 option
2184 specifies the soft limits instead.
2185 When displaying limits,
2186 only one of
2187 .Fl S
2188 or
2189 .Fl H
2190 can be given.
2191 The default is to display the soft limits,
2192 and to set both the hard and the soft limits.
2193 .Pp
2194 Option
2195 .Fl a
2196 causes the
2197 .Ic ulimit
2198 command to display all resources.
2199 The parameter
2200 .Ar limit
2201 is not acceptable in this mode.
2202 .Pp
2203 The remaining options specify which resource value is to be
2204 displayed or modified.
2205 They are mutually exclusive.
2206 .Bl -tag -width indent
2207 .It Fl b Ar sbsize
2208 The maximum size of socket buffer usage, in bytes.
2209 .It Fl c Ar coredumpsize
2210 The maximal size of core dump files, in 512-byte blocks.
2211 .It Fl d Ar datasize
2212 The maximal size of the data segment of a process, in kilobytes.
2213 .It Fl f Ar filesize
2214 The maximal size of a file, in 512-byte blocks.
2215 .It Fl l Ar lockedmem
2216 The maximal size of memory that can be locked by a process, in
2217 kilobytes.
2218 .It Fl m Ar memoryuse
2219 The maximal resident set size of a process, in kilobytes.
2220 .It Fl n Ar nofiles
2221 The maximal number of descriptors that could be opened by a process.
2222 .It Fl p Ar pseudoterminals
2223 The maximal number of pseudo-terminals for this user ID.
2224 .It Fl s Ar stacksize
2225 The maximal size of the stack segment, in kilobytes.
2226 .It Fl t Ar time
2227 The maximal amount of CPU time to be used by each process, in seconds.
2228 .It Fl u Ar userproc
2229 The maximal number of simultaneous processes for this user ID.
2230 .It Fl v Ar virtualmem
2231 The maximal virtual size of a process, in kilobytes.
2232 .It Fl w Ar swapuse
2233 The maximum amount of swap space reserved or used for this user ID,
2234 in kilobytes.
2235 .El
2236 .It Ic umask Oo Fl S Oc Op Ar mask
2237 Set the file creation mask (see
2238 .Xr umask 2 )
2239 to the octal or symbolic (see
2240 .Xr chmod 1 )
2241 value specified by
2242 .Ar mask .
2243 If the argument is omitted, the current mask value is printed.
2244 If the
2245 .Fl S
2246 option is specified, the output is symbolic, otherwise the output is octal.
2247 .It Ic unalias Oo Fl a Oc Op Ar name ...
2248 The specified alias names are removed.
2249 If
2250 .Fl a
2251 is specified, all aliases are removed.
2252 .It Ic unset Oo Fl fv Oc Ar name ...
2253 The specified variables or functions are unset and unexported.
2254 If the
2255 .Fl v
2256 option is specified or no options are given, the
2257 .Ar name
2258 arguments are treated as variable names.
2259 If the
2260 .Fl f
2261 option is specified, the
2262 .Ar name
2263 arguments are treated as function names.
2264 .It Ic wait Op Ar job
2265 Wait for the specified
2266 .Ar job
2267 to complete and return the exit status of the last process in the
2268 .Ar job .
2269 If the argument is omitted, wait for all jobs to complete
2270 and return an exit status of zero.
2271 .El
2272 .Ss Commandline Editing
2273 When
2274 .Nm
2275 is being used interactively from a terminal, the current command
2276 and the command history
2277 (see
2278 .Ic fc
2279 in
2280 .Sx Built-in Commands )
2281 can be edited using
2282 .Nm vi Ns -mode
2283 command line editing.
2284 This mode uses commands similar
2285 to a subset of those described in the
2286 .Xr vi 1
2287 man page.
2288 The command
2289 .Dq Li "set -o vi"
2290 (or
2291 .Dq Li "set -V" )
2292 enables
2293 .Nm vi Ns -mode
2294 editing and places
2295 .Nm
2296 into
2297 .Nm vi
2298 insert mode.
2299 With
2300 .Nm vi Ns -mode
2301 enabled,
2302 .Nm
2303 can be switched between insert mode and command mode by typing
2304 .Aq ESC .
2305 Hitting
2306 .Aq return
2307 while in command mode will pass the line to the shell.
2308 .Pp
2309 Similarly, the
2310 .Dq Li "set -o emacs"
2311 (or
2312 .Dq Li "set -E" )
2313 command can be used to enable a subset of
2314 .Nm emacs Ns -style
2315 command line editing features.
2316 .Sh ENVIRONMENT
2317 The following environment variables affect the execution of
2318 .Nm :
2319 .Bl -tag -width ".Ev HISTSIZE"
2320 .It Ev CDPATH
2321 The search path used with the
2322 .Ic cd
2323 built-in.
2324 .It Ev EDITOR
2325 The fallback editor used with the
2326 .Ic fc
2327 built-in.
2328 If not set, the default editor is
2329 .Xr ed 1 .
2330 .It Ev FCEDIT
2331 The default editor used with the
2332 .Ic fc
2333 built-in.
2334 .It Ev HISTSIZE
2335 The number of previous commands that are accessible.
2336 .It Ev HOME
2337 The starting directory of
2338 .Nm .
2339 .It Ev IFS
2340 Input Field Separators.
2341 This is normally set to
2342 .Aq space ,
2343 .Aq tab ,
2344 and
2345 .Aq newline .
2346 See the
2347 .Sx White Space Splitting
2348 section for more details.
2349 .It Ev MAIL
2350 The name of a mail file, that will be checked for the arrival of new
2351 mail.
2352 Overridden by
2353 .Ev MAILPATH .
2354 .It Ev MAILPATH
2355 A colon
2356 .Pq Ql \&:
2357 separated list of file names, for the shell to check for incoming
2358 mail.
2359 This environment setting overrides the
2360 .Ev MAIL
2361 setting.
2362 There is a maximum of 10 mailboxes that can be monitored at once.
2363 .It Ev PATH
2364 The default search path for executables.
2365 See the
2366 .Sx Path Search
2367 section for details.
2368 .It Ev PS1
2369 The primary prompt string, which defaults to
2370 .Dq Li "$ " ,
2371 unless you are the superuser, in which case it defaults to
2372 .Dq Li "# " .
2373 .It Ev PS2
2374 The secondary prompt string, which defaults to
2375 .Dq Li "> " .
2376 .It Ev PS4
2377 The prefix for the trace output (if
2378 .Fl x
2379 is active).
2380 The default is
2381 .Dq Li "+ " .
2382 .It Ev TERM
2383 The default terminal setting for the shell.
2384 This is inherited by children of the shell, and is used in the history
2385 editing modes.
2386 .El
2387 .Sh EXIT STATUS
2388 Errors that are detected by the shell, such as a syntax error, will
2389 cause the shell to exit with a non-zero exit status.
2390 If the shell is not an interactive shell, the execution of the shell
2391 file will be aborted.
2392 Otherwise the shell will return the exit status of the last command
2393 executed, or if the
2394 .Ic exit
2395 builtin is used with a numeric argument, it
2396 will return the argument.
2397 .Sh SEE ALSO
2398 .Xr builtin 1 ,
2399 .Xr chsh 1 ,
2400 .Xr echo 1 ,
2401 .Xr ed 1 ,
2402 .Xr emacs 1 ,
2403 .Xr pwd 1 ,
2404 .Xr test 1 ,
2405 .Xr vi 1 ,
2406 .Xr execve 2 ,
2407 .Xr getrlimit 2 ,
2408 .Xr umask 2 ,
2409 .Xr editrc 5
2410 .Sh HISTORY
2411 A
2412 .Nm
2413 command, the Thompson shell, appeared in
2414 .At v1 .
2415 It was superseded in
2416 .At v7
2417 by the Bourne shell, which inherited the name
2418 .Nm .
2419 .Pp
2420 This version of
2421 .Nm
2422 was rewritten in 1989 under the
2423 .Bx
2424 license after the Bourne shell from
2425 .At V.4 .
2426 .Sh AUTHORS
2427 This version of
2428 .Nm
2429 was originally written by
2430 .An Kenneth Almquist .
2431 .Sh BUGS
2432 The
2433 .Nm
2434 utility does not recognize multibyte characters.