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