]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - bin/sh/sh.1
MFC r213926: sh(1): Clarify subshells/processes for pipelines.
[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 October 16, 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 Note that unlike some other shells,
736 .Nm
737 executes each process in a pipeline with more than one command
738 in a subshell environment and as a child of the
739 .Nm
740 process.
741 .Pp
742 If the pipeline is not in the background (discussed later),
743 the shell waits for all commands to complete.
744 .Pp
745 If the keyword
746 .Ic !\&
747 does not precede the pipeline, the
748 exit status is the exit status of the last command specified
749 in the pipeline.
750 Otherwise, the exit status is the logical
751 NOT of the exit status of the last command.
752 That is, if
753 the last command returns zero, the exit status is 1; if
754 the last command returns greater than zero, the exit status
755 is zero.
756 .Pp
757 Because pipeline assignment of standard input or standard
758 output or both takes place before redirection, it can be
759 modified by redirection.
760 For example:
761 .Pp
762 .Dl "command1 2>&1 | command2"
763 .Pp
764 sends both the standard output and standard error of
765 .Ar command1
766 to the standard input of
767 .Ar command2 .
768 .Pp
769 A
770 .Ql \&;
771 or newline terminator causes the preceding
772 AND-OR-list
773 (described below in the section called
774 .Sx Short-Circuit List Operators )
775 to be executed sequentially;
776 an
777 .Ql &
778 causes asynchronous execution of the preceding AND-OR-list.
779 .Ss Background Commands (&)
780 If a command is terminated by the control operator ampersand
781 .Pq Ql & ,
782 the shell executes the command asynchronously;
783 the shell does not wait for the command to finish
784 before executing the next command.
785 .Pp
786 The format for running a command in background is:
787 .Pp
788 .D1 Ar command1 Li & Op Ar command2 Li & Ar ...
789 .Pp
790 If the shell is not interactive, the standard input of an
791 asynchronous command is set to
792 .Pa /dev/null .
793 .Ss Lists (Generally Speaking)
794 A list is a sequence of zero or more commands separated by
795 newlines, semicolons, or ampersands,
796 and optionally terminated by one of these three characters.
797 The commands in a
798 list are executed in the order they are written.
799 If command is followed by an ampersand, the shell starts the
800 command and immediately proceeds onto the next command;
801 otherwise it waits for the command to terminate before
802 proceeding to the next one.
803 .Ss Short-Circuit List Operators
804 .Dq Li &&
805 and
806 .Dq Li ||
807 are AND-OR list operators.
808 .Dq Li &&
809 executes the first command, and then executes the second command
810 if the exit status of the first command is zero.
811 .Dq Li ||
812 is similar, but executes the second command if the exit
813 status of the first command is nonzero.
814 .Dq Li &&
815 and
816 .Dq Li ||
817 both have the same priority.
818 .Ss Flow-Control Constructs (if, while, for, case)
819 The syntax of the
820 .Ic if
821 command is:
822 .Bd -unfilled -offset indent -compact
823 .Ic if Ar list
824 .Ic then Ar list
825 .Oo Ic elif Ar list
826 .Ic then Ar list Oc Ar ...
827 .Op Ic else Ar list
828 .Ic fi
829 .Ed
830 .Pp
831 The syntax of the
832 .Ic while
833 command is:
834 .Bd -unfilled -offset indent -compact
835 .Ic while Ar list
836 .Ic do Ar list
837 .Ic done
838 .Ed
839 .Pp
840 The two lists are executed repeatedly while the exit status of the
841 first list is zero.
842 The
843 .Ic until
844 command is similar, but has the word
845 .Ic until
846 in place of
847 .Ic while ,
848 which causes it to
849 repeat until the exit status of the first list is zero.
850 .Pp
851 The syntax of the
852 .Ic for
853 command is:
854 .Bd -unfilled -offset indent -compact
855 .Ic for Ar variable Op Ic in Ar word ...
856 .Ic do Ar list
857 .Ic done
858 .Ed
859 .Pp
860 If
861 .Ic in
862 and the following words are omitted,
863 .Ic in Li \&"$@\&"
864 is used instead.
865 The words are expanded, and then the list is executed
866 repeatedly with the variable set to each word in turn.
867 The
868 .Ic do
869 and
870 .Ic done
871 commands may be replaced with
872 .Ql {
873 and
874 .Ql } .
875 .Pp
876 The syntax of the
877 .Ic break
878 and
879 .Ic continue
880 commands is:
881 .D1 Ic break Op Ar num
882 .D1 Ic continue Op Ar num
883 .Pp
884 The
885 .Ic break
886 command terminates the
887 .Ar num
888 innermost
889 .Ic for
890 or
891 .Ic while
892 loops.
893 The
894 .Ic continue
895 command continues with the next iteration of the innermost loop.
896 These are implemented as special built-in commands.
897 .Pp
898 The syntax of the
899 .Ic case
900 command is:
901 .Bd -unfilled -offset indent -compact
902 .Ic case Ar word Ic in
903 .Ar pattern Ns Li ) Ar list Li ;;
904 .Ar ...
905 .Ic esac
906 .Ed
907 .Pp
908 The pattern can actually be one or more patterns
909 (see
910 .Sx Shell Patterns
911 described later),
912 separated by
913 .Ql \&|
914 characters.
915 The exit code of the
916 .Ic case
917 command is the exit code of the last command executed in the list or
918 zero if no patterns were matched.
919 .Ss Grouping Commands Together
920 Commands may be grouped by writing either
921 .Pp
922 .D1 Li \&( Ns Ar list Ns Li \%)
923 .Pp
924 or
925 .Pp
926 .D1 Li { Ar list Ns Li \&; }
927 .Pp
928 The first form executes the commands in a subshell.
929 Note that built-in commands thus executed do not affect the current shell.
930 The second form does not fork another shell,
931 so it is slightly more efficient.
932 Grouping commands together this way allows the user to
933 redirect their output as though they were one program:
934 .Bd -literal -offset indent
935 { echo -n "hello"; echo " world"; } > greeting
936 .Ed
937 .Ss Functions
938 The syntax of a function definition is
939 .Pp
940 .D1 Ar name Li \&( \&) Ar command
941 .Pp
942 A function definition is an executable statement; when
943 executed it installs a function named
944 .Ar name
945 and returns an
946 exit status of zero.
947 The
948 .Ar command
949 is normally a list
950 enclosed between
951 .Ql {
952 and
953 .Ql } .
954 .Pp
955 Variables may be declared to be local to a function by
956 using the
957 .Ic local
958 command.
959 This should appear as the first statement of a function,
960 and the syntax is:
961 .Pp
962 .D1 Ic local Oo Ar variable ... Oc Op Fl
963 .Pp
964 The
965 .Ic local
966 command is implemented as a built-in command.
967 .Pp
968 When a variable is made local, it inherits the initial
969 value and exported and readonly flags from the variable
970 with the same name in the surrounding scope, if there is
971 one.
972 Otherwise, the variable is initially unset.
973 The shell
974 uses dynamic scoping, so that if the variable
975 .Va x
976 is made local to function
977 .Em f ,
978 which then calls function
979 .Em g ,
980 references to the variable
981 .Va x
982 made inside
983 .Em g
984 will refer to the variable
985 .Va x
986 declared inside
987 .Em f ,
988 not to the global variable named
989 .Va x .
990 .Pp
991 The only special parameter that can be made local is
992 .Ql - .
993 Making
994 .Ql -
995 local causes any shell options that are
996 changed via the
997 .Ic set
998 command inside the function to be
999 restored to their original values when the function
1000 returns.
1001 .Pp
1002 The syntax of the
1003 .Ic return
1004 command is
1005 .Pp
1006 .D1 Ic return Op Ar exitstatus
1007 .Pp
1008 It terminates the current executional scope, returning from the previous
1009 nested function, sourced script, or shell instance, in that order.
1010 The
1011 .Ic return
1012 command is implemented as a special built-in command.
1013 .Ss Variables and Parameters
1014 The shell maintains a set of parameters.
1015 A parameter
1016 denoted by a name is called a variable.
1017 When starting up,
1018 the shell turns all the environment variables into shell
1019 variables.
1020 New variables can be set using the form
1021 .Pp
1022 .D1 Ar name Ns = Ns Ar value
1023 .Pp
1024 Variables set by the user must have a name consisting solely
1025 of alphabetics, numerics, and underscores.
1026 The first letter of a variable name must not be numeric.
1027 A parameter can also be denoted by a number
1028 or a special character as explained below.
1029 .Ss Positional Parameters
1030 A positional parameter is a parameter denoted by a number greater than zero.
1031 The shell sets these initially to the values of its command line
1032 arguments that follow the name of the shell script.
1033 The
1034 .Ic set
1035 built-in command can also be used to set or reset them.
1036 .Ss Special Parameters
1037 A special parameter is a parameter denoted by a special one-character
1038 name.
1039 The special parameters recognized by the
1040 .Nm
1041 shell of
1042 .Fx
1043 are shown in the following list, exactly as they would appear in input
1044 typed by the user or in the source of a shell script.
1045 .Bl -hang
1046 .It Li $*
1047 Expands to the positional parameters, starting from one.
1048 When
1049 the expansion occurs within a double-quoted string
1050 it expands to a single field with the value of each parameter
1051 separated by the first character of the
1052 .Va IFS
1053 variable,
1054 or by a space if
1055 .Va IFS
1056 is unset.
1057 .It Li $@
1058 Expands to the positional parameters, starting from one.
1059 When
1060 the expansion occurs within double-quotes, each positional
1061 parameter expands as a separate argument.
1062 If there are no positional parameters, the
1063 expansion of
1064 .Li @
1065 generates zero arguments, even when
1066 .Li @
1067 is double-quoted.
1068 What this basically means, for example, is
1069 if
1070 .Li $1
1071 is
1072 .Dq Li abc
1073 and
1074 .Li $2
1075 is
1076 .Dq Li "def ghi" ,
1077 then
1078 .Li \&"$@\&"
1079 expands to
1080 the two arguments:
1081 .Bd -literal -offset indent
1082 "abc"   "def ghi"
1083 .Ed
1084 .It Li $#
1085 Expands to the number of positional parameters.
1086 .It Li $?
1087 Expands to the exit status of the most recent pipeline.
1088 .It Li $-
1089 (hyphen) Expands to the current option flags (the single-letter
1090 option names concatenated into a string) as specified on
1091 invocation, by the
1092 .Ic set
1093 built-in command, or implicitly
1094 by the shell.
1095 .It Li $$
1096 Expands to the process ID of the invoked shell.
1097 A subshell
1098 retains the same value of
1099 .Va $
1100 as its parent.
1101 .It Li $!
1102 Expands to the process ID of the most recent background
1103 command executed from the current shell.
1104 For a
1105 pipeline, the process ID is that of the last command in the
1106 pipeline.
1107 .It Li $0
1108 (zero) Expands to the name of the shell or shell script.
1109 .El
1110 .Ss Word Expansions
1111 This clause describes the various expansions that are
1112 performed on words.
1113 Not all expansions are performed on
1114 every word, as explained later.
1115 .Pp
1116 Tilde expansions, parameter expansions, command substitutions,
1117 arithmetic expansions, and quote removals that occur within
1118 a single word expand to a single field.
1119 It is only field
1120 splitting or pathname expansion that can create multiple
1121 fields from a single word.
1122 The single exception to this rule is
1123 the expansion of the special parameter
1124 .Va @
1125 within double-quotes,
1126 as was described above.
1127 .Pp
1128 The order of word expansion is:
1129 .Bl -enum
1130 .It
1131 Tilde Expansion, Parameter Expansion, Command Substitution,
1132 Arithmetic Expansion (these all occur at the same time).
1133 .It
1134 Field Splitting is performed on fields generated by step (1)
1135 unless the
1136 .Va IFS
1137 variable is null.
1138 .It
1139 Pathname Expansion (unless the
1140 .Fl f
1141 option is in effect).
1142 .It
1143 Quote Removal.
1144 .El
1145 .Pp
1146 The
1147 .Ql $
1148 character is used to introduce parameter expansion, command
1149 substitution, or arithmetic expansion.
1150 .Ss Tilde Expansion (substituting a user's home directory)
1151 A word beginning with an unquoted tilde character
1152 .Pq Ql ~
1153 is
1154 subjected to tilde expansion.
1155 All the characters up to a slash
1156 .Pq Ql /
1157 or the end of the word are treated as a username
1158 and are replaced with the user's home directory.
1159 If the
1160 username is missing (as in
1161 .Pa ~/foobar ) ,
1162 the tilde is replaced with the value of the
1163 .Ev HOME
1164 variable (the current user's home directory).
1165 .Ss Parameter Expansion
1166 The format for parameter expansion is as follows:
1167 .Pp
1168 .D1 Li ${ Ns Ar expression Ns Li }
1169 .Pp
1170 where
1171 .Ar expression
1172 consists of all characters until the matching
1173 .Ql } .
1174 Any
1175 .Ql }
1176 escaped by a backslash or within a quoted string, and characters in
1177 embedded arithmetic expansions, command substitutions, and variable
1178 expansions, are not examined in determining the matching
1179 .Ql } .
1180 .Pp
1181 The simplest form for parameter expansion is:
1182 .Pp
1183 .D1 Li ${ Ns Ar parameter Ns Li }
1184 .Pp
1185 The value, if any, of
1186 .Ar parameter
1187 is substituted.
1188 .Pp
1189 The parameter name or symbol can be enclosed in braces, which are
1190 optional except for positional parameters with more than one digit or
1191 when parameter is followed by a character that could be interpreted as
1192 part of the name.
1193 If a parameter expansion occurs inside double-quotes:
1194 .Bl -enum
1195 .It
1196 Pathname expansion is not performed on the results of the
1197 expansion.
1198 .It
1199 Field splitting is not performed on the results of the
1200 expansion, with the exception of the special parameter
1201 .Va @ .
1202 .El
1203 .Pp
1204 In addition, a parameter expansion can be modified by using one of the
1205 following formats.
1206 .Bl -tag -width indent
1207 .It Li ${ Ns Ar parameter Ns Li :- Ns Ar word Ns Li }
1208 Use Default Values.
1209 If
1210 .Ar parameter
1211 is unset or null, the expansion of
1212 .Ar word
1213 is substituted; otherwise, the value of
1214 .Ar parameter
1215 is substituted.
1216 .It Li ${ Ns Ar parameter Ns Li := Ns Ar word Ns Li }
1217 Assign Default Values.
1218 If
1219 .Ar parameter
1220 is unset or null, the expansion of
1221 .Ar word
1222 is assigned to
1223 .Ar parameter .
1224 In all cases, the
1225 final value of
1226 .Ar parameter
1227 is substituted.
1228 Quoting inside
1229 .Ar word
1230 does not prevent field splitting or pathname expansion.
1231 Only variables, not positional
1232 parameters or special parameters, can be
1233 assigned in this way.
1234 .It Li ${ Ns Ar parameter Ns Li :? Ns Oo Ar word Oc Ns Li }
1235 Indicate Error if Null or Unset.
1236 If
1237 .Ar parameter
1238 is unset or null, the expansion of
1239 .Ar word
1240 (or a message indicating it is unset if
1241 .Ar word
1242 is omitted) is written to standard
1243 error and the shell exits with a nonzero
1244 exit status.
1245 Otherwise, the value of
1246 .Ar parameter
1247 is substituted.
1248 An
1249 interactive shell need not exit.
1250 .It Li ${ Ns Ar parameter Ns Li :+ Ns Ar word Ns Li }
1251 Use Alternate Value.
1252 If
1253 .Ar parameter
1254 is unset or null, null is substituted;
1255 otherwise, the expansion of
1256 .Ar word
1257 is substituted.
1258 .El
1259 .Pp
1260 In the parameter expansions shown previously, use of the colon in the
1261 format results in a test for a parameter that is unset or null; omission
1262 of the colon results in a test for a parameter that is only unset.
1263 .Bl -tag -width indent
1264 .It Li ${# Ns Ar parameter Ns Li }
1265 String Length.
1266 The length in characters of
1267 the value of
1268 .Ar parameter .
1269 .El
1270 .Pp
1271 The following four varieties of parameter expansion provide for substring
1272 processing.
1273 In each case, pattern matching notation
1274 (see
1275 .Sx Shell Patterns ) ,
1276 rather than regular expression notation,
1277 is used to evaluate the patterns.
1278 If parameter is one of the special parameters
1279 .Va *
1280 or
1281 .Va @ ,
1282 the result of the expansion is unspecified.
1283 Enclosing the full parameter expansion string in double-quotes does not
1284 cause the following four varieties of pattern characters to be quoted,
1285 whereas quoting characters within the braces has this effect.
1286 .Bl -tag -width indent
1287 .It Li ${ Ns Ar parameter Ns Li % Ns Ar word Ns Li }
1288 Remove Smallest Suffix Pattern.
1289 The
1290 .Ar word
1291 is expanded to produce a pattern.
1292 The
1293 parameter expansion then results in
1294 .Ar parameter ,
1295 with the smallest portion of the
1296 suffix matched by the pattern deleted.
1297 .It Li ${ Ns Ar parameter Ns Li %% Ns Ar word Ns Li }
1298 Remove Largest Suffix Pattern.
1299 The
1300 .Ar word
1301 is expanded to produce a pattern.
1302 The
1303 parameter expansion then results in
1304 .Ar parameter ,
1305 with the largest portion of the
1306 suffix matched by the pattern deleted.
1307 .It Li ${ Ns Ar parameter Ns Li # Ns Ar word Ns Li }
1308 Remove Smallest Prefix Pattern.
1309 The
1310 .Ar word
1311 is expanded to produce a pattern.
1312 The
1313 parameter expansion then results in
1314 .Ar parameter ,
1315 with the smallest portion of the
1316 prefix matched by the pattern deleted.
1317 .It Li ${ Ns Ar parameter Ns Li ## Ns Ar word Ns Li }
1318 Remove Largest Prefix Pattern.
1319 The
1320 .Ar word
1321 is expanded to produce a pattern.
1322 The
1323 parameter expansion then results in
1324 .Ar parameter ,
1325 with the largest portion of the
1326 prefix matched by the pattern deleted.
1327 .El
1328 .Ss Command Substitution
1329 Command substitution allows the output of a command to be substituted in
1330 place of the command name itself.
1331 Command substitution occurs when
1332 the command is enclosed as follows:
1333 .Pp
1334 .D1 Li $( Ns Ar command Ns Li )\&
1335 .Pp
1336 or the backquoted version:
1337 .Pp
1338 .D1 Li ` Ns Ar command Ns Li `
1339 .Pp
1340 The shell expands the command substitution by executing command in a
1341 subshell environment and replacing the command substitution
1342 with the standard output of the command,
1343 removing sequences of one or more newlines at the end of the substitution.
1344 Embedded newlines before the end of the output are not removed;
1345 however, during field splitting, they may be translated into spaces
1346 depending on the value of
1347 .Va IFS
1348 and the quoting that is in effect.
1349 .Ss Arithmetic Expansion
1350 Arithmetic expansion provides a mechanism for evaluating an arithmetic
1351 expression and substituting its value.
1352 The format for arithmetic expansion is as follows:
1353 .Pp
1354 .D1 Li $(( Ns Ar expression Ns Li ))
1355 .Pp
1356 The
1357 .Ar expression
1358 is treated as if it were in double-quotes, except
1359 that a double-quote inside the expression is not treated specially.
1360 The
1361 shell expands all tokens in the
1362 .Ar expression
1363 for parameter expansion,
1364 command substitution,
1365 arithmetic expansion
1366 and quote removal.
1367 .Pp
1368 The allowed expressions are a subset of C expressions,
1369 summarized below.
1370 .Bl -tag -width "Variables" -offset indent
1371 .It Values
1372 All values are of type
1373 .Ft intmax_t .
1374 .It Constants
1375 Decimal, octal (starting with
1376 .Li 0 )
1377 and hexadecimal (starting with 
1378 .Li 0x )
1379 integer constants.
1380 .It Variables
1381 Shell variables can be read and written
1382 and contain integer constants.
1383 .It Unary operators
1384 .Li "! ~ + -"
1385 .It Binary operators
1386 .Li "* / % + - << >> < <= > >= == != & ^ | && ||"
1387 .It Assignment operators
1388 .Li "= += -= *= /= %= <<= >>= &= ^= |="
1389 .It Short-circuit evaluation
1390 The
1391 .Li &&
1392 and
1393 .Li ||
1394 operators always evaluate both sides.
1395 This is a bug.
1396 .El
1397 .Pp
1398 The result of the expression is substituted in decimal.
1399 .Ss White Space Splitting (Field Splitting)
1400 After parameter expansion, command substitution, and
1401 arithmetic expansion the shell scans the results of
1402 expansions and substitutions that did not occur in double-quotes for
1403 field splitting and multiple fields can result.
1404 .Pp
1405 The shell treats each character of the
1406 .Va IFS
1407 variable as a delimiter and uses
1408 the delimiters to split the results of parameter expansion and command
1409 substitution into fields.
1410 .Ss Pathname Expansion (File Name Generation)
1411 Unless the
1412 .Fl f
1413 option is set,
1414 file name generation is performed
1415 after word splitting is complete.
1416 Each word is
1417 viewed as a series of patterns, separated by slashes.
1418 The
1419 process of expansion replaces the word with the names of
1420 all existing files whose names can be formed by replacing
1421 each pattern with a string that matches the specified pattern.
1422 There are two restrictions on this: first, a pattern cannot match
1423 a string containing a slash, and second,
1424 a pattern cannot match a string starting with a period
1425 unless the first character of the pattern is a period.
1426 The next section describes the patterns used for both
1427 Pathname Expansion and the
1428 .Ic case
1429 command.
1430 .Ss Shell Patterns
1431 A pattern consists of normal characters, which match themselves,
1432 and meta-characters.
1433 The meta-characters are
1434 .Ql \&! ,
1435 .Ql * ,
1436 .Ql \&? ,
1437 and
1438 .Ql \&[ .
1439 These characters lose their special meanings if they are quoted.
1440 When command or variable substitution is performed and the dollar sign
1441 or back quotes are not double-quoted, the value of the
1442 variable or the output of the command is scanned for these
1443 characters and they are turned into meta-characters.
1444 .Pp
1445 An asterisk
1446 .Pq Ql *
1447 matches any string of characters.
1448 A question mark
1449 .Pq Ql \&?
1450 matches any single character.
1451 A left bracket
1452 .Pq Ql \&[
1453 introduces a character class.
1454 The end of the character class is indicated by a
1455 .Ql \&] ;
1456 if the
1457 .Ql \&]
1458 is missing then the
1459 .Ql \&[
1460 matches a
1461 .Ql \&[
1462 rather than introducing a character class.
1463 A character class matches any of the characters between the square brackets.
1464 A range of characters may be specified using a minus sign.
1465 The character class may be complemented by making an exclamation point
1466 .Pq Ql !\&
1467 the first character of the character class.
1468 .Pp
1469 To include a
1470 .Ql \&]
1471 in a character class, make it the first character listed
1472 (after the
1473 .Ql \&! ,
1474 if any).
1475 To include a
1476 .Ql - ,
1477 make it the first or last character listed.
1478 .Ss Built-in Commands
1479 This section lists the commands which
1480 are built-in because they need to perform some operation
1481 that cannot be performed by a separate process.
1482 In addition to
1483 these, built-in versions of essential utilities
1484 are provided for efficiency.
1485 .Bl -tag -width indent
1486 .It Ic \&:
1487 A null command that returns a 0 (true) exit value.
1488 .It Ic \&. Ar file
1489 The commands in the specified file are read and executed by the shell.
1490 The
1491 .Ic return
1492 command may be used to return to the
1493 .Ic \&.
1494 command's caller.
1495 If
1496 .Ar file
1497 contains any
1498 .Ql /
1499 characters, it is used as is.
1500 Otherwise, the shell searches the
1501 .Ev PATH
1502 for the file.
1503 If it is not found in the
1504 .Ev PATH ,
1505 it is sought in the current working directory.
1506 .It Ic \&[
1507 A built-in equivalent of
1508 .Xr test 1 .
1509 .It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc
1510 If
1511 .Ar name Ns = Ns Ar string
1512 is specified, the shell defines the alias
1513 .Ar name
1514 with value
1515 .Ar string .
1516 If just
1517 .Ar name
1518 is specified, the value of the alias
1519 .Ar name
1520 is printed.
1521 With no arguments, the
1522 .Ic alias
1523 built-in command prints the names and values of all defined aliases
1524 (see
1525 .Ic unalias ) .
1526 Alias values are written with appropriate quoting so that they are
1527 suitable for re-input to the shell.
1528 Also see the
1529 .Sx Aliases
1530 subsection.
1531 .It Ic bg Op Ar job ...
1532 Continue the specified jobs
1533 (or the current job if no jobs are given)
1534 in the background.
1535 .It Ic builtin Ar cmd Op Ar arg ...
1536 Execute the specified built-in command,
1537 .Ar cmd .
1538 This is useful when the user wishes to override a shell function
1539 with the same name as a built-in command.
1540 .It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc
1541 List or alter key bindings for the line editor.
1542 This command is documented in
1543 .Xr editrc 5 .
1544 .It Ic cd Oo Fl L | P Oc Op Ar directory
1545 Switch to the specified
1546 .Ar directory ,
1547 or to the directory specified in the
1548 .Ev HOME
1549 environment variable if no
1550 .Ar directory
1551 is specified.
1552 If
1553 .Ar directory
1554 does not begin with
1555 .Pa / , \&. ,
1556 or
1557 .Pa .. ,
1558 then the directories listed in the
1559 .Ev CDPATH
1560 variable will be
1561 searched for the specified
1562 .Ar directory .
1563 If
1564 .Ev CDPATH
1565 is unset, the current directory is searched.
1566 The format of
1567 .Ev CDPATH
1568 is the same as that of
1569 .Ev PATH .
1570 In an interactive shell,
1571 the
1572 .Ic cd
1573 command will print out the name of the directory
1574 that it actually switched to
1575 if this is different from the name that the user gave.
1576 These may be different either because the
1577 .Ev CDPATH
1578 mechanism was used or because a symbolic link was crossed.
1579 .Pp
1580 If the
1581 .Fl P
1582 option is specified,
1583 .Pa ..
1584 is handled physically and symbolic links are resolved before
1585 .Pa ..
1586 components are processed.
1587 If the
1588 .Fl L
1589 option is specified,
1590 .Pa ..
1591 is handled logically.
1592 This is the default.
1593 .It Ic chdir
1594 A synonym for the
1595 .Ic cd
1596 built-in command.
1597 .It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ...
1598 .It Ic command Oo Fl v | V Oc Op Ar utility
1599 The first form of invocation executes the specified
1600 .Ar utility
1601 as a simple command (see the
1602 .Sx Simple Commands
1603 section).
1604 .Pp
1605 If the
1606 .Fl p
1607 option is specified, the command search is performed using a
1608 default value of
1609 .Ev PATH
1610 that is guaranteed to find all of the standard utilities.
1611 .Pp
1612 If the
1613 .Fl v
1614 option is specified,
1615 .Ar utility
1616 is not executed but a description of its interpretation by the shell is
1617 printed.
1618 For ordinary commands the output is the path name; for shell built-in
1619 commands, shell functions and keywords only the name is written.
1620 Aliases are printed as
1621 .Dq Ic alias Ar name Ns = Ns Ar value .
1622 .Pp
1623 The
1624 .Fl V
1625 option is identical to
1626 .Fl v
1627 except for the output.
1628 It prints
1629 .Dq Ar utility Ic is Ar description
1630 where
1631 .Ar description
1632 is either
1633 the path name to
1634 .Ar utility ,
1635 a special shell builtin,
1636 a shell builtin,
1637 a shell function,
1638 a shell keyword
1639 or
1640 an alias for
1641 .Ar value .
1642 .It Ic echo Oo Fl e | n Oc Op Ar string ...
1643 Print a space-separated list of the arguments to the standard output
1644 and append a newline character.
1645 .Bl -tag -width indent
1646 .It Fl n
1647 Suppress the output of the trailing newline.
1648 .It Fl e
1649 Process C-style backslash escape sequences.
1650 The
1651 .Ic echo
1652 command understands the following character escapes:
1653 .Bl -tag -width indent
1654 .It \ea
1655 Alert (ring the terminal bell)
1656 .It \eb
1657 Backspace
1658 .It \ec
1659 Suppress the trailing newline (this has the side-effect of truncating the
1660 line if it is not the last character)
1661 .It \ee
1662 The ESC character
1663 .Tn ( ASCII
1664 0x1b)
1665 .It \ef
1666 Formfeed
1667 .It \en
1668 Newline
1669 .It \er
1670 Carriage return
1671 .It \et
1672 Horizontal tab
1673 .It \ev
1674 Vertical tab
1675 .It \e\e
1676 Literal backslash
1677 .It \e0nnn
1678 (Zero) The character whose octal value is
1679 .Ar nnn
1680 .El
1681 .Pp
1682 If
1683 .Ar string
1684 is not enclosed in quotes then the backslash itself must be escaped
1685 with a backslash to protect it from the shell.
1686 For example
1687 .Bd -literal -offset indent
1688 $ echo -e "a\evb"
1689 a
1690  b
1691 $ echo -e a\e\evb
1692 a
1693  b
1694 $ echo -e "a\e\eb"
1695 a\eb
1696 $ echo -e a\e\e\e\eb
1697 a\eb
1698 .Ed
1699 .El
1700 .Pp
1701 Only one of the
1702 .Fl e
1703 and
1704 .Fl n
1705 options may be specified.
1706 .It Ic eval Ar string ...
1707 Concatenate all the arguments with spaces.
1708 Then re-parse and execute the command.
1709 .It Ic exec Op Ar command Op arg ...
1710 Unless
1711 .Ar command
1712 is omitted,
1713 the shell process is replaced with the specified program
1714 (which must be a real program, not a shell built-in command or function).
1715 Any redirections on the
1716 .Ic exec
1717 command are marked as permanent,
1718 so that they are not undone when the
1719 .Ic exec
1720 command finishes.
1721 .It Ic exit Op Ar exitstatus
1722 Terminate the shell process.
1723 If
1724 .Ar exitstatus
1725 is given
1726 it is used as the exit status of the shell;
1727 otherwise the exit status of the preceding command is used.
1728 The exit status should be an integer between 0 and 255.
1729 .It Ic export Ar name ...
1730 .It Ic export Op Fl p
1731 The specified names are exported so that they will
1732 appear in the environment of subsequent commands.
1733 The only way to un-export a variable is to
1734 .Ic unset
1735 it.
1736 The shell allows the value of a variable to be set
1737 at the same time as it is exported by writing
1738 .Pp
1739 .D1 Ic export Ar name Ns = Ns Ar value
1740 .Pp
1741 With no arguments the
1742 .Ic export
1743 command lists the names
1744 of all exported variables.
1745 If the
1746 .Fl p
1747 option is specified, the exported variables are printed as
1748 .Dq Ic export Ar name Ns = Ns Ar value
1749 lines, suitable for re-input to the shell.
1750 .It Ic false
1751 A null command that returns a non-zero (false) exit value.
1752 .It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last
1753 .It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last
1754 .It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first
1755 The
1756 .Ic fc
1757 built-in command lists, or edits and re-executes,
1758 commands previously entered to an interactive shell.
1759 .Bl -tag -width indent
1760 .It Fl e Ar editor
1761 Use the editor named by
1762 .Ar editor
1763 to edit the commands.
1764 The
1765 .Ar editor
1766 string is a command name,
1767 subject to search via the
1768 .Ev PATH
1769 variable.
1770 The value in the
1771 .Ev FCEDIT
1772 variable is used as a default when
1773 .Fl e
1774 is not specified.
1775 If
1776 .Ev FCEDIT
1777 is null or unset, the value of the
1778 .Ev EDITOR
1779 variable is used.
1780 If
1781 .Ev EDITOR
1782 is null or unset,
1783 .Xr ed 1
1784 is used as the editor.
1785 .It Fl l No (ell)
1786 List the commands rather than invoking
1787 an editor on them.
1788 The commands are written in the
1789 sequence indicated by the
1790 .Ar first
1791 and
1792 .Ar last
1793 operands, as affected by
1794 .Fl r ,
1795 with each command preceded by the command number.
1796 .It Fl n
1797 Suppress command numbers when listing with
1798 .Fl l .
1799 .It Fl r
1800 Reverse the order of the commands listed
1801 (with
1802 .Fl l )
1803 or edited
1804 (with neither
1805 .Fl l
1806 nor
1807 .Fl s ) .
1808 .It Fl s
1809 Re-execute the command without invoking an editor.
1810 .It Ar first
1811 .It Ar last
1812 Select the commands to list or edit.
1813 The number of previous commands that can be accessed
1814 are determined by the value of the
1815 .Ev HISTSIZE
1816 variable.
1817 The value of
1818 .Ar first
1819 or
1820 .Ar last
1821 or both are one of the following:
1822 .Bl -tag -width indent
1823 .It Oo Cm + Oc Ns Ar num
1824 A positive number representing a command number;
1825 command numbers can be displayed with the
1826 .Fl l
1827 option.
1828 .It Fl Ar num
1829 A negative decimal number representing the
1830 command that was executed
1831 .Ar num
1832 of
1833 commands previously.
1834 For example, \-1 is the immediately previous command.
1835 .It Ar string
1836 A string indicating the most recently entered command
1837 that begins with that string.
1838 If the
1839 .Ar old Ns = Ns Ar new
1840 operand is not also specified with
1841 .Fl s ,
1842 the string form of the first operand cannot contain an embedded equal sign.
1843 .El
1844 .El
1845 .Pp
1846 The following environment variables affect the execution of
1847 .Ic fc :
1848 .Bl -tag -width ".Ev HISTSIZE"
1849 .It Ev FCEDIT
1850 Name of the editor to use for history editing.
1851 .It Ev HISTSIZE
1852 The number of previous commands that are accessible.
1853 .El
1854 .It Ic fg Op Ar job
1855 Move the specified
1856 .Ar job
1857 or the current job to the foreground.
1858 .It Ic getopts Ar optstring var
1859 The
1860 .Tn POSIX
1861 .Ic getopts
1862 command.
1863 The
1864 .Ic getopts
1865 command deprecates the older
1866 .Xr getopt 1
1867 command.
1868 The first argument should be a series of letters, each possibly
1869 followed by a colon which indicates that the option takes an argument.
1870 The specified variable is set to the parsed option.
1871 The index of
1872 the next argument is placed into the shell variable
1873 .Va OPTIND .
1874 If an option takes an argument, it is placed into the shell variable
1875 .Va OPTARG .
1876 If an invalid option is encountered,
1877 .Ar var
1878 is set to
1879 .Ql \&? .
1880 It returns a false value (1) when it encounters the end of the options.
1881 .It Ic hash Oo Fl rv Oc Op Ar command ...
1882 The shell maintains a hash table which remembers the locations of commands.
1883 With no arguments whatsoever, the
1884 .Ic hash
1885 command prints out the contents of this table.
1886 Entries which have not been looked at since the last
1887 .Ic cd
1888 command are marked with an asterisk;
1889 it is possible for these entries to be invalid.
1890 .Pp
1891 With arguments, the
1892 .Ic hash
1893 command removes each specified
1894 .Ar command
1895 from the hash table (unless they are functions) and then locates it.
1896 With the
1897 .Fl v
1898 option,
1899 .Ic hash
1900 prints the locations of the commands as it finds them.
1901 The
1902 .Fl r
1903 option causes the
1904 .Ic hash
1905 command to delete all the entries in the hash table except for functions.
1906 .It Ic jobid Op Ar job
1907 Print the process IDs of the processes in the specified
1908 .Ar job .
1909 If the
1910 .Ar job
1911 argument is omitted, use the current job.
1912 .It Ic jobs Oo Fl lps Oc Op Ar job ...
1913 Print information about the specified jobs, or all jobs if no
1914 .Ar job
1915 argument is given.
1916 The information printed includes job ID, status and command name.
1917 .Pp
1918 If the
1919 .Fl l
1920 option is specified, the PID of each job is also printed.
1921 If the
1922 .Fl p
1923 option is specified, only the process IDs for the process group leaders
1924 are printed, one per line.
1925 If the
1926 .Fl s
1927 option is specified, only the PIDs of the job commands are printed, one per
1928 line.
1929 .It Ic local Oo Ar variable ... Oc Op Fl
1930 See the
1931 .Sx Functions
1932 subsection.
1933 .It Ic pwd Op Fl L | P
1934 Print the path of the current directory.
1935 The built-in command may
1936 differ from the program of the same name because the
1937 built-in command remembers what the current directory
1938 is rather than recomputing it each time.
1939 This makes
1940 it faster.
1941 However, if the current directory is
1942 renamed,
1943 the built-in version of
1944 .Xr pwd 1
1945 will continue to print the old name for the directory.
1946 .Pp
1947 If the
1948 .Fl P
1949 option is specified, symbolic links are resolved.
1950 If the
1951 .Fl L
1952 option is specified, the shell's notion of the current directory
1953 is printed (symbolic links are not resolved).
1954 This is the default.
1955 .It Ic read Oo Fl p Ar prompt Oc Oo
1956 .Fl t Ar timeout Oc Oo Fl er Oc Ar variable ...
1957 The
1958 .Ar prompt
1959 is printed if the
1960 .Fl p
1961 option is specified
1962 and the standard input is a terminal.
1963 Then a line is
1964 read from the standard input.
1965 The trailing newline
1966 is deleted from the line and the line is split as
1967 described in the section on
1968 .Sx White Space Splitting (Field Splitting)
1969 above, and
1970 the pieces are assigned to the variables in order.
1971 If there are more pieces than variables, the remaining
1972 pieces (along with the characters in
1973 .Va IFS
1974 that separated them)
1975 are assigned to the last variable.
1976 If there are more variables than pieces, the remaining
1977 variables are assigned the null string.
1978 .Pp
1979 Backslashes are treated specially, unless the
1980 .Fl r
1981 option is
1982 specified.
1983 If a backslash is followed by
1984 a newline, the backslash and the newline will be
1985 deleted.
1986 If a backslash is followed by any other
1987 character, the backslash will be deleted and the following
1988 character will be treated as though it were not in
1989 .Va IFS ,
1990 even if it is.
1991 .Pp
1992 If the
1993 .Fl t
1994 option is specified and the
1995 .Ar timeout
1996 elapses before a complete line of input is supplied,
1997 the
1998 .Ic read
1999 command will return an exit status of 1 without assigning any values.
2000 The
2001 .Ar timeout
2002 value may optionally be followed by one of
2003 .Ql s ,
2004 .Ql m
2005 or
2006 .Ql h
2007 to explicitly specify seconds, minutes or hours.
2008 If none is supplied,
2009 .Ql s
2010 is assumed.
2011 .Pp
2012 The
2013 .Fl e
2014 option exists only for backward compatibility with older scripts.
2015 .It Ic readonly Oo Fl p Oc Op Ar name ...
2016 Each specified
2017 .Ar name
2018 is marked as read only,
2019 so that it cannot be subsequently modified or unset.
2020 The shell allows the value of a variable to be set
2021 at the same time as it is marked read only
2022 by using the following form:
2023 .Pp
2024 .D1 Ic readonly Ar name Ns = Ns Ar value
2025 .Pp
2026 With no arguments the
2027 .Ic readonly
2028 command lists the names of all read only variables.
2029 If the
2030 .Fl p
2031 option is specified, the read-only variables are printed as
2032 .Dq Ic readonly Ar name Ns = Ns Ar value
2033 lines, suitable for re-input to the shell.
2034 .It Ic return Op Ar exitstatus
2035 See the
2036 .Sx Functions
2037 subsection.
2038 .It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo
2039 .Fl c Ar string Oc Op Fl - Ar arg ...
2040 The
2041 .Ic set
2042 command performs three different functions:
2043 .Bl -item
2044 .It
2045 With no arguments, it lists the values of all shell variables.
2046 .It
2047 If options are given,
2048 either in short form or using the long
2049 .Dq Fl /+o Ar longname
2050 form,
2051 it sets or clears the specified options as described in the section called
2052 .Sx Argument List Processing .
2053 .It
2054 If the
2055 .Dq Fl -
2056 option is specified,
2057 .Ic set
2058 will replace the shell's positional parameters with the subsequent
2059 arguments.
2060 If no arguments follow the
2061 .Dq Fl -
2062 option,
2063 all the positional parameters will be cleared,
2064 which is equivalent to executing the command
2065 .Dq Li "shift $#" .
2066 The
2067 .Dq Fl -
2068 flag may be omitted when specifying arguments to be used
2069 as positional replacement parameters.
2070 This is not recommended,
2071 because the first argument may begin with a dash
2072 .Pq Ql -
2073 or a plus
2074 .Pq Ql + ,
2075 which the
2076 .Ic set
2077 command will interpret as a request to enable or disable options.
2078 .El
2079 .It Ic setvar Ar variable value
2080 Assigns the specified
2081 .Ar value
2082 to the specified
2083 .Ar variable .
2084 The
2085 .Ic setvar
2086 command is intended to be used in functions that
2087 assign values to variables whose names are passed as parameters.
2088 In general it is better to write
2089 .Dq Ar variable Ns = Ns Ar value
2090 rather than using
2091 .Ic setvar .
2092 .It Ic shift Op Ar n
2093 Shift the positional parameters
2094 .Ar n
2095 times, or once if
2096 .Ar n
2097 is not specified.
2098 A shift sets the value of
2099 .Li $1
2100 to the value of
2101 .Li $2 ,
2102 the value of
2103 .Li $2
2104 to the value of
2105 .Li $3 ,
2106 and so on,
2107 decreasing the value of
2108 .Li $#
2109 by one.
2110 If there are zero positional parameters, shifting does not do anything.
2111 .It Ic test
2112 A built-in equivalent of
2113 .Xr test 1 .
2114 .It Ic times
2115 Print the amount of time spent executing the shell and its children.
2116 The first output line shows the user and system times for the shell
2117 itself, the second one contains the user and system times for the
2118 children.
2119 .It Ic trap Oo Ar action Oc Ar signal ...
2120 .It Ic trap Fl l
2121 Cause the shell to parse and execute
2122 .Ar action
2123 when any specified
2124 .Ar signal
2125 is received.
2126 The signals are specified by name or number.
2127 In addition, the pseudo-signal
2128 .Cm EXIT
2129 may be used to specify an
2130 .Ar action
2131 that is performed when the shell terminates.
2132 The
2133 .Ar action
2134 may be an empty string or a dash
2135 .Pq Ql - ;
2136 the former causes the specified signal to be ignored
2137 and the latter causes the default action to be taken.
2138 Omitting the
2139 .Ar action
2140 is another way to request the default action, for compatibility reasons this
2141 usage is not recommended though.
2142 When the shell forks off a subshell,
2143 it resets trapped (but not ignored) signals to the default action.
2144 The
2145 .Ic trap
2146 command has no effect on signals that were ignored on entry to the shell.
2147 .Pp
2148 Option
2149 .Fl l
2150 causes the
2151 .Ic trap
2152 command to display a list of valid signal names.
2153 .It Ic true
2154 A null command that returns a 0 (true) exit value.
2155 .It Ic type Op Ar name ...
2156 Interpret each
2157 .Ar name
2158 as a command and print the resolution of the command search.
2159 Possible resolutions are:
2160 shell keyword, alias, special shell builtin, shell builtin, command,
2161 tracked alias
2162 and not found.
2163 For aliases the alias expansion is printed;
2164 for commands and tracked aliases
2165 the complete pathname of the command is printed.
2166 .It Ic ulimit Oo Fl HSabcdflmnpstuvw Oc Op Ar limit
2167 Set or display resource limits (see
2168 .Xr getrlimit 2 ) .
2169 If
2170 .Ar limit
2171 is specified, the named resource will be set;
2172 otherwise the current resource value will be displayed.
2173 .Pp
2174 If
2175 .Fl H
2176 is specified, the hard limits will be set or displayed.
2177 While everybody is allowed to reduce a hard limit,
2178 only the superuser can increase it.
2179 The
2180 .Fl S
2181 option
2182 specifies the soft limits instead.
2183 When displaying limits,
2184 only one of
2185 .Fl S
2186 or
2187 .Fl H
2188 can be given.
2189 The default is to display the soft limits,
2190 and to set both the hard and the soft limits.
2191 .Pp
2192 Option
2193 .Fl a
2194 causes the
2195 .Ic ulimit
2196 command to display all resources.
2197 The parameter
2198 .Ar limit
2199 is not acceptable in this mode.
2200 .Pp
2201 The remaining options specify which resource value is to be
2202 displayed or modified.
2203 They are mutually exclusive.
2204 .Bl -tag -width indent
2205 .It Fl b Ar sbsize
2206 The maximum size of socket buffer usage, in bytes.
2207 .It Fl c Ar coredumpsize
2208 The maximal size of core dump files, in 512-byte blocks.
2209 .It Fl d Ar datasize
2210 The maximal size of the data segment of a process, in kilobytes.
2211 .It Fl f Ar filesize
2212 The maximal size of a file, in 512-byte blocks.
2213 .It Fl l Ar lockedmem
2214 The maximal size of memory that can be locked by a process, in
2215 kilobytes.
2216 .It Fl m Ar memoryuse
2217 The maximal resident set size of a process, in kilobytes.
2218 .It Fl n Ar nofiles
2219 The maximal number of descriptors that could be opened by a process.
2220 .It Fl p Ar pseudoterminals
2221 The maximal number of pseudo-terminals for this user ID.
2222 .It Fl s Ar stacksize
2223 The maximal size of the stack segment, in kilobytes.
2224 .It Fl t Ar time
2225 The maximal amount of CPU time to be used by each process, in seconds.
2226 .It Fl u Ar userproc
2227 The maximal number of simultaneous processes for this user ID.
2228 .It Fl v Ar virtualmem
2229 The maximal virtual size of a process, in kilobytes.
2230 .It Fl w Ar swapuse
2231 The maximum amount of swap space reserved or used for this user ID,
2232 in kilobytes.
2233 .El
2234 .It Ic umask Oo Fl S Oc Op Ar mask
2235 Set the file creation mask (see
2236 .Xr umask 2 )
2237 to the octal or symbolic (see
2238 .Xr chmod 1 )
2239 value specified by
2240 .Ar mask .
2241 If the argument is omitted, the current mask value is printed.
2242 If the
2243 .Fl S
2244 option is specified, the output is symbolic, otherwise the output is octal.
2245 .It Ic unalias Oo Fl a Oc Op Ar name ...
2246 The specified alias names are removed.
2247 If
2248 .Fl a
2249 is specified, all aliases are removed.
2250 .It Ic unset Oo Fl fv Oc Ar name ...
2251 The specified variables or functions are unset and unexported.
2252 If the
2253 .Fl v
2254 option is specified or no options are given, the
2255 .Ar name
2256 arguments are treated as variable names.
2257 If the
2258 .Fl f
2259 option is specified, the
2260 .Ar name
2261 arguments are treated as function names.
2262 .It Ic wait Op Ar job
2263 Wait for the specified
2264 .Ar job
2265 to complete and return the exit status of the last process in the
2266 .Ar job .
2267 If the argument is omitted, wait for all jobs to complete
2268 and return an exit status of zero.
2269 .El
2270 .Ss Commandline Editing
2271 When
2272 .Nm
2273 is being used interactively from a terminal, the current command
2274 and the command history
2275 (see
2276 .Ic fc
2277 in
2278 .Sx Built-in Commands )
2279 can be edited using
2280 .Nm vi Ns -mode
2281 command line editing.
2282 This mode uses commands similar
2283 to a subset of those described in the
2284 .Xr vi 1
2285 man page.
2286 The command
2287 .Dq Li "set -o vi"
2288 (or
2289 .Dq Li "set -V" )
2290 enables
2291 .Nm vi Ns -mode
2292 editing and places
2293 .Nm
2294 into
2295 .Nm vi
2296 insert mode.
2297 With
2298 .Nm vi Ns -mode
2299 enabled,
2300 .Nm
2301 can be switched between insert mode and command mode by typing
2302 .Aq ESC .
2303 Hitting
2304 .Aq return
2305 while in command mode will pass the line to the shell.
2306 .Pp
2307 Similarly, the
2308 .Dq Li "set -o emacs"
2309 (or
2310 .Dq Li "set -E" )
2311 command can be used to enable a subset of
2312 .Nm emacs Ns -style
2313 command line editing features.
2314 .Sh ENVIRONMENT
2315 The following environment variables affect the execution of
2316 .Nm :
2317 .Bl -tag -width ".Ev HISTSIZE"
2318 .It Ev CDPATH
2319 The search path used with the
2320 .Ic cd
2321 built-in.
2322 .It Ev EDITOR
2323 The fallback editor used with the
2324 .Ic fc
2325 built-in.
2326 If not set, the default editor is
2327 .Xr ed 1 .
2328 .It Ev FCEDIT
2329 The default editor used with the
2330 .Ic fc
2331 built-in.
2332 .It Ev HISTSIZE
2333 The number of previous commands that are accessible.
2334 .It Ev HOME
2335 The starting directory of
2336 .Nm .
2337 .It Ev IFS
2338 Input Field Separators.
2339 This is normally set to
2340 .Aq space ,
2341 .Aq tab ,
2342 and
2343 .Aq newline .
2344 See the
2345 .Sx White Space Splitting
2346 section for more details.
2347 .It Ev MAIL
2348 The name of a mail file, that will be checked for the arrival of new
2349 mail.
2350 Overridden by
2351 .Ev MAILPATH .
2352 .It Ev MAILPATH
2353 A colon
2354 .Pq Ql \&:
2355 separated list of file names, for the shell to check for incoming
2356 mail.
2357 This environment setting overrides the
2358 .Ev MAIL
2359 setting.
2360 There is a maximum of 10 mailboxes that can be monitored at once.
2361 .It Ev PATH
2362 The default search path for executables.
2363 See the
2364 .Sx Path Search
2365 section for details.
2366 .It Ev PS1
2367 The primary prompt string, which defaults to
2368 .Dq Li "$ " ,
2369 unless you are the superuser, in which case it defaults to
2370 .Dq Li "# " .
2371 .It Ev PS2
2372 The secondary prompt string, which defaults to
2373 .Dq Li "> " .
2374 .It Ev PS4
2375 The prefix for the trace output (if
2376 .Fl x
2377 is active).
2378 The default is
2379 .Dq Li "+ " .
2380 .It Ev TERM
2381 The default terminal setting for the shell.
2382 This is inherited by children of the shell, and is used in the history
2383 editing modes.
2384 .El
2385 .Sh EXIT STATUS
2386 Errors that are detected by the shell, such as a syntax error, will
2387 cause the shell to exit with a non-zero exit status.
2388 If the shell is not an interactive shell, the execution of the shell
2389 file will be aborted.
2390 Otherwise the shell will return the exit status of the last command
2391 executed, or if the
2392 .Ic exit
2393 builtin is used with a numeric argument, it
2394 will return the argument.
2395 .Sh SEE ALSO
2396 .Xr builtin 1 ,
2397 .Xr chsh 1 ,
2398 .Xr echo 1 ,
2399 .Xr ed 1 ,
2400 .Xr emacs 1 ,
2401 .Xr pwd 1 ,
2402 .Xr test 1 ,
2403 .Xr vi 1 ,
2404 .Xr execve 2 ,
2405 .Xr getrlimit 2 ,
2406 .Xr umask 2 ,
2407 .Xr editrc 5
2408 .Sh HISTORY
2409 A
2410 .Nm
2411 command, the Thompson shell, appeared in
2412 .At v1 .
2413 It was superseded in
2414 .At v7
2415 by the Bourne shell, which inherited the name
2416 .Nm .
2417 .Pp
2418 This version of
2419 .Nm
2420 was rewritten in 1989 under the
2421 .Bx
2422 license after the Bourne shell from
2423 .At V.4 .
2424 .Sh AUTHORS
2425 This version of
2426 .Nm
2427 was originally written by
2428 .An Kenneth Almquist .
2429 .Sh BUGS
2430 The
2431 .Nm
2432 utility does not recognize multibyte characters.