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