xref: /freebsd/bin/sh/sh.1 (revision 884a2a699669ec61e2366e3e358342dbc94be24a)
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 May 21, 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 reads commands from the file named in
128.Ev ENV .
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)
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
1540and the substitutions in the command cannot cause side effects
1541(such as from assigning values to variables or referencing
1542.Li $! ).
1543.Ss Arithmetic Expansion
1544Arithmetic expansion provides a mechanism for evaluating an arithmetic
1545expression and substituting its value.
1546The format for arithmetic expansion is as follows:
1547.Pp
1548.D1 Li $(( Ns Ar expression Ns Li ))
1549.Pp
1550The
1551.Ar expression
1552is treated as if it were in double-quotes, except
1553that a double-quote inside the expression is not treated specially.
1554The
1555shell expands all tokens in the
1556.Ar expression
1557for parameter expansion,
1558command substitution,
1559arithmetic expansion
1560and quote removal.
1561.Pp
1562The allowed expressions are a subset of C expressions,
1563summarized below.
1564.Bl -tag -width "Variables" -offset indent
1565.It Values
1566All values are of type
1567.Ft intmax_t .
1568.It Constants
1569Decimal, octal (starting with
1570.Li 0 )
1571and hexadecimal (starting with
1572.Li 0x )
1573integer constants.
1574.It Variables
1575Shell variables can be read and written
1576and contain integer constants.
1577.It Unary operators
1578.Li "! ~ + -"
1579.It Binary operators
1580.Li "* / % + - << >> < <= > >= == != & ^ | && ||"
1581.It Assignment operators
1582.Li "= += -= *= /= %= <<= >>= &= ^= |="
1583.It Conditional operator
1584.Li "? :"
1585.El
1586.Pp
1587The result of the expression is substituted in decimal.
1588.Ss White Space Splitting (Field Splitting)
1589After parameter expansion, command substitution, and
1590arithmetic expansion the shell scans the results of
1591expansions and substitutions that did not occur in double-quotes for
1592field splitting and multiple fields can result.
1593.Pp
1594The shell treats each character of the
1595.Va IFS
1596variable as a delimiter and uses
1597the delimiters to split the results of parameter expansion and command
1598substitution into fields.
1599.Ss Pathname Expansion (File Name Generation)
1600Unless the
1601.Fl f
1602option is set,
1603file name generation is performed
1604after word splitting is complete.
1605Each word is
1606viewed as a series of patterns, separated by slashes.
1607The
1608process of expansion replaces the word with the names of
1609all existing files whose names can be formed by replacing
1610each pattern with a string that matches the specified pattern.
1611There are two restrictions on this: first, a pattern cannot match
1612a string containing a slash, and second,
1613a pattern cannot match a string starting with a period
1614unless the first character of the pattern is a period.
1615The next section describes the patterns used for both
1616Pathname Expansion and the
1617.Ic case
1618command.
1619.Ss Shell Patterns
1620A pattern consists of normal characters, which match themselves,
1621and meta-characters.
1622The meta-characters are
1623.Ql \&! ,
1624.Ql * ,
1625.Ql \&? ,
1626and
1627.Ql \&[ .
1628These characters lose their special meanings if they are quoted.
1629When command or variable substitution is performed and the dollar sign
1630or back quotes are not double-quoted, the value of the
1631variable or the output of the command is scanned for these
1632characters and they are turned into meta-characters.
1633.Pp
1634An asterisk
1635.Pq Ql *
1636matches any string of characters.
1637A question mark
1638.Pq Ql \&?
1639matches any single character.
1640A left bracket
1641.Pq Ql \&[
1642introduces a character class.
1643The end of the character class is indicated by a
1644.Ql \&] ;
1645if the
1646.Ql \&]
1647is missing then the
1648.Ql \&[
1649matches a
1650.Ql \&[
1651rather than introducing a character class.
1652A character class matches any of the characters between the square brackets.
1653A range of characters may be specified using a minus sign.
1654The character class may be complemented by making an exclamation point
1655.Pq Ql !\&
1656the first character of the character class.
1657.Pp
1658To include a
1659.Ql \&]
1660in a character class, make it the first character listed
1661(after the
1662.Ql \&! ,
1663if any).
1664To include a
1665.Ql - ,
1666make it the first or last character listed.
1667.Ss Built-in Commands
1668This section lists the built-in commands.
1669.Bl -tag -width indent
1670.It Ic \&:
1671A null command that returns a 0 (true) exit value.
1672.It Ic \&. Ar file
1673The commands in the specified file are read and executed by the shell.
1674The
1675.Ic return
1676command may be used to return to the
1677.Ic \&.
1678command's caller.
1679If
1680.Ar file
1681contains any
1682.Ql /
1683characters, it is used as is.
1684Otherwise, the shell searches the
1685.Va PATH
1686for the file.
1687If it is not found in the
1688.Va PATH ,
1689it is sought in the current working directory.
1690.It Ic \&[
1691A built-in equivalent of
1692.Xr test 1 .
1693.It Ic alias Oo Ar name Ns Oo = Ns Ar string Oc ... Oc
1694If
1695.Ar name Ns = Ns Ar string
1696is specified, the shell defines the alias
1697.Ar name
1698with value
1699.Ar string .
1700If just
1701.Ar name
1702is specified, the value of the alias
1703.Ar name
1704is printed.
1705With no arguments, the
1706.Ic alias
1707built-in command prints the names and values of all defined aliases
1708(see
1709.Ic unalias ) .
1710Alias values are written with appropriate quoting so that they are
1711suitable for re-input to the shell.
1712Also see the
1713.Sx Aliases
1714subsection.
1715.It Ic bg Op Ar job ...
1716Continue the specified jobs
1717(or the current job if no jobs are given)
1718in the background.
1719.It Ic bind Oo Fl aeklrsv Oc Oo Ar key Oo Ar command Oc Oc
1720List or alter key bindings for the line editor.
1721This command is documented in
1722.Xr editrc 5 .
1723.It Ic break Op Ar num
1724See the
1725.Sx Flow-Control Constructs
1726subsection.
1727.It Ic builtin Ar cmd Op Ar arg ...
1728Execute the specified built-in command,
1729.Ar cmd .
1730This is useful when the user wishes to override a shell function
1731with the same name as a built-in command.
1732.It Ic cd Oo Fl L | P Oc Oo Fl e Oc Op Ar directory
1733Switch to the specified
1734.Ar directory ,
1735or to the directory specified in the
1736.Va HOME
1737environment variable if no
1738.Ar directory
1739is specified.
1740If
1741.Ar directory
1742does not begin with
1743.Pa / , \&. ,
1744or
1745.Pa .. ,
1746then the directories listed in the
1747.Va CDPATH
1748variable will be
1749searched for the specified
1750.Ar directory .
1751If
1752.Va CDPATH
1753is unset, the current directory is searched.
1754The format of
1755.Va CDPATH
1756is the same as that of
1757.Va PATH .
1758In an interactive shell,
1759the
1760.Ic cd
1761command will print out the name of the directory
1762that it actually switched to
1763if this is different from the name that the user gave.
1764These may be different either because the
1765.Va CDPATH
1766mechanism was used or because a symbolic link was crossed.
1767.Pp
1768If the
1769.Fl P
1770option is specified,
1771.Pa ..
1772is handled physically and symbolic links are resolved before
1773.Pa ..
1774components are processed.
1775If the
1776.Fl L
1777option is specified,
1778.Pa ..
1779is handled logically.
1780This is the default.
1781.Pp
1782The
1783.Fl e
1784option causes
1785.Ic cd
1786to return exit status 1 if the full pathname of the new directory
1787cannot be determined reliably or at all.
1788Normally this is not considered an error,
1789although a warning is printed.
1790.It Ic chdir
1791A synonym for the
1792.Ic cd
1793built-in command.
1794.It Ic command Oo Fl p Oc Op Ar utility Op Ar argument ...
1795.It Ic command Oo Fl p Oc Fl v Ar utility
1796.It Ic command Oo Fl p Oc Fl V Ar utility
1797The first form of invocation executes the specified
1798.Ar utility ,
1799ignoring shell functions in the search.
1800If
1801.Ar utility
1802is a special builtin,
1803it is executed as if it were a regular builtin.
1804.Pp
1805If the
1806.Fl p
1807option is specified, the command search is performed using a
1808default value of
1809.Va PATH
1810that is guaranteed to find all of the standard utilities.
1811.Pp
1812If the
1813.Fl v
1814option is specified,
1815.Ar utility
1816is not executed but a description of its interpretation by the shell is
1817printed.
1818For ordinary commands the output is the path name; for shell built-in
1819commands, shell functions and keywords only the name is written.
1820Aliases are printed as
1821.Dq Ic alias Ar name Ns = Ns Ar value .
1822.Pp
1823The
1824.Fl V
1825option is identical to
1826.Fl v
1827except for the output.
1828It prints
1829.Dq Ar utility Ic is Ar description
1830where
1831.Ar description
1832is either
1833the path name to
1834.Ar utility ,
1835a special shell builtin,
1836a shell builtin,
1837a shell function,
1838a shell keyword
1839or
1840an alias for
1841.Ar value .
1842.It Ic continue Op Ar num
1843See the
1844.Sx Flow-Control Constructs
1845subsection.
1846.It Ic echo Oo Fl e | n Oc Op Ar string ...
1847Print a space-separated list of the arguments to the standard output
1848and append a newline character.
1849.Bl -tag -width indent
1850.It Fl n
1851Suppress the output of the trailing newline.
1852.It Fl e
1853Process C-style backslash escape sequences.
1854The
1855.Ic echo
1856command understands the following character escapes:
1857.Bl -tag -width indent
1858.It \ea
1859Alert (ring the terminal bell)
1860.It \eb
1861Backspace
1862.It \ec
1863Suppress the trailing newline (this has the side-effect of truncating the
1864line if it is not the last character)
1865.It \ee
1866The ESC character
1867.Tn ( ASCII
18680x1b)
1869.It \ef
1870Formfeed
1871.It \en
1872Newline
1873.It \er
1874Carriage return
1875.It \et
1876Horizontal tab
1877.It \ev
1878Vertical tab
1879.It \e\e
1880Literal backslash
1881.It \e0nnn
1882(Zero) The character whose octal value is
1883.Ar nnn
1884.El
1885.Pp
1886If
1887.Ar string
1888is not enclosed in quotes then the backslash itself must be escaped
1889with a backslash to protect it from the shell.
1890For example
1891.Bd -literal -offset indent
1892$ echo -e "a\evb"
1893a
1894 b
1895$ echo -e a\e\evb
1896a
1897 b
1898$ echo -e "a\e\eb"
1899a\eb
1900$ echo -e a\e\e\e\eb
1901a\eb
1902.Ed
1903.El
1904.Pp
1905Only one of the
1906.Fl e
1907and
1908.Fl n
1909options may be specified.
1910.It Ic eval Ar string ...
1911Concatenate all the arguments with spaces.
1912Then re-parse and execute the command.
1913.It Ic exec Op Ar command Op arg ...
1914Unless
1915.Ar command
1916is omitted,
1917the shell process is replaced with the specified program
1918(which must be a real program, not a shell built-in command or function).
1919Any redirections on the
1920.Ic exec
1921command are marked as permanent,
1922so that they are not undone when the
1923.Ic exec
1924command finishes.
1925.It Ic exit Op Ar exitstatus
1926Terminate the shell process.
1927If
1928.Ar exitstatus
1929is given
1930it is used as the exit status of the shell.
1931Otherwise, if the shell is executing an
1932.Cm EXIT
1933trap, the exit status of the last command before the trap is used;
1934if the shell is executing a trap for a signal,
1935the shell exits by resending the signal to itself.
1936Otherwise, the exit status of the preceding command is used.
1937The exit status should be an integer between 0 and 255.
1938.It Ic export Ar name ...
1939.It Ic export Op Fl p
1940The specified names are exported so that they will
1941appear in the environment of subsequent commands.
1942The only way to un-export a variable is to
1943.Ic unset
1944it.
1945The shell allows the value of a variable to be set
1946at the same time as it is exported by writing
1947.Pp
1948.D1 Ic export Ar name Ns = Ns Ar value
1949.Pp
1950With no arguments the
1951.Ic export
1952command lists the names
1953of all exported variables.
1954If the
1955.Fl p
1956option is specified, the exported variables are printed as
1957.Dq Ic export Ar name Ns = Ns Ar value
1958lines, suitable for re-input to the shell.
1959.It Ic false
1960A null command that returns a non-zero (false) exit value.
1961.It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last
1962.It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last
1963.It Ic fc Fl s Oo Ar old Ns = Ns Ar new Oc Op Ar first
1964The
1965.Ic fc
1966built-in command lists, or edits and re-executes,
1967commands previously entered to an interactive shell.
1968.Bl -tag -width indent
1969.It Fl e Ar editor
1970Use the editor named by
1971.Ar editor
1972to edit the commands.
1973The
1974.Ar editor
1975string is a command name,
1976subject to search via the
1977.Va PATH
1978variable.
1979The value in the
1980.Va FCEDIT
1981variable is used as a default when
1982.Fl e
1983is not specified.
1984If
1985.Va FCEDIT
1986is null or unset, the value of the
1987.Va EDITOR
1988variable is used.
1989If
1990.Va EDITOR
1991is null or unset,
1992.Xr ed 1
1993is used as the editor.
1994.It Fl l No (ell)
1995List the commands rather than invoking
1996an editor on them.
1997The commands are written in the
1998sequence indicated by the
1999.Ar first
2000and
2001.Ar last
2002operands, as affected by
2003.Fl r ,
2004with each command preceded by the command number.
2005.It Fl n
2006Suppress command numbers when listing with
2007.Fl l .
2008.It Fl r
2009Reverse the order of the commands listed
2010(with
2011.Fl l )
2012or edited
2013(with neither
2014.Fl l
2015nor
2016.Fl s ) .
2017.It Fl s
2018Re-execute the command without invoking an editor.
2019.It Ar first
2020.It Ar last
2021Select the commands to list or edit.
2022The number of previous commands that can be accessed
2023are determined by the value of the
2024.Va HISTSIZE
2025variable.
2026The value of
2027.Ar first
2028or
2029.Ar last
2030or both are one of the following:
2031.Bl -tag -width indent
2032.It Oo Cm + Oc Ns Ar num
2033A positive number representing a command number;
2034command numbers can be displayed with the
2035.Fl l
2036option.
2037.It Fl Ar num
2038A negative decimal number representing the
2039command that was executed
2040.Ar num
2041of
2042commands previously.
2043For example, \-1 is the immediately previous command.
2044.It Ar string
2045A string indicating the most recently entered command
2046that begins with that string.
2047If the
2048.Ar old Ns = Ns Ar new
2049operand is not also specified with
2050.Fl s ,
2051the string form of the first operand cannot contain an embedded equal sign.
2052.El
2053.El
2054.Pp
2055The following variables affect the execution of
2056.Ic fc :
2057.Bl -tag -width ".Va HISTSIZE"
2058.It Va FCEDIT
2059Name of the editor to use for history editing.
2060.It Va HISTSIZE
2061The number of previous commands that are accessible.
2062.El
2063.It Ic fg Op Ar job
2064Move the specified
2065.Ar job
2066or the current job to the foreground.
2067.It Ic getopts Ar optstring var
2068The
2069.Tn POSIX
2070.Ic getopts
2071command.
2072The
2073.Ic getopts
2074command deprecates the older
2075.Xr getopt 1
2076command.
2077The first argument should be a series of letters, each possibly
2078followed by a colon which indicates that the option takes an argument.
2079The specified variable is set to the parsed option.
2080The index of
2081the next argument is placed into the shell variable
2082.Va OPTIND .
2083If an option takes an argument, it is placed into the shell variable
2084.Va OPTARG .
2085If an invalid option is encountered,
2086.Ar var
2087is set to
2088.Ql \&? .
2089It returns a false value (1) when it encounters the end of the options.
2090.It Ic hash Oo Fl rv Oc Op Ar command ...
2091The shell maintains a hash table which remembers the locations of commands.
2092With no arguments whatsoever, the
2093.Ic hash
2094command prints out the contents of this table.
2095Entries which have not been looked at since the last
2096.Ic cd
2097command are marked with an asterisk;
2098it is possible for these entries to be invalid.
2099.Pp
2100With arguments, the
2101.Ic hash
2102command removes each specified
2103.Ar command
2104from the hash table (unless they are functions) and then locates it.
2105With the
2106.Fl v
2107option,
2108.Ic hash
2109prints the locations of the commands as it finds them.
2110The
2111.Fl r
2112option causes the
2113.Ic hash
2114command to delete all the entries in the hash table except for functions.
2115.It Ic jobid Op Ar job
2116Print the process IDs of the processes in the specified
2117.Ar job .
2118If the
2119.Ar job
2120argument is omitted, use the current job.
2121.It Ic jobs Oo Fl lps Oc Op Ar job ...
2122Print information about the specified jobs, or all jobs if no
2123.Ar job
2124argument is given.
2125The information printed includes job ID, status and command name.
2126.Pp
2127If the
2128.Fl l
2129option is specified, the PID of each job is also printed.
2130If the
2131.Fl p
2132option is specified, only the process IDs for the process group leaders
2133are printed, one per line.
2134If the
2135.Fl s
2136option is specified, only the PIDs of the job commands are printed, one per
2137line.
2138.It Ic kill
2139A built-in equivalent of
2140.Xr kill 1
2141that additionally supports sending signals to jobs.
2142.It Ic local Oo Ar variable ... Oc Op Fl
2143See the
2144.Sx Functions
2145subsection.
2146.It Ic printf
2147A built-in equivalent of
2148.Xr printf 1 .
2149.It Ic pwd Op Fl L | P
2150Print the path of the current directory.
2151The built-in command may
2152differ from the program of the same name because the
2153built-in command remembers what the current directory
2154is rather than recomputing it each time.
2155This makes
2156it faster.
2157However, if the current directory is
2158renamed,
2159the built-in version of
2160.Xr pwd 1
2161will continue to print the old name for the directory.
2162.Pp
2163If the
2164.Fl P
2165option is specified, symbolic links are resolved.
2166If the
2167.Fl L
2168option is specified, the shell's notion of the current directory
2169is printed (symbolic links are not resolved).
2170This is the default.
2171.It Ic read Oo Fl p Ar prompt Oc Oo
2172.Fl t Ar timeout Oc Oo Fl er Oc Ar variable ...
2173The
2174.Ar prompt
2175is printed if the
2176.Fl p
2177option is specified
2178and the standard input is a terminal.
2179Then a line is
2180read from the standard input.
2181The trailing newline
2182is deleted from the line and the line is split as
2183described in the section on
2184.Sx White Space Splitting (Field Splitting)
2185above, and
2186the pieces are assigned to the variables in order.
2187If there are more pieces than variables, the remaining
2188pieces (along with the characters in
2189.Va IFS
2190that separated them)
2191are assigned to the last variable.
2192If there are more variables than pieces, the remaining
2193variables are assigned the null string.
2194.Pp
2195Backslashes are treated specially, unless the
2196.Fl r
2197option is
2198specified.
2199If a backslash is followed by
2200a newline, the backslash and the newline will be
2201deleted.
2202If a backslash is followed by any other
2203character, the backslash will be deleted and the following
2204character will be treated as though it were not in
2205.Va IFS ,
2206even if it is.
2207.Pp
2208If the
2209.Fl t
2210option is specified and the
2211.Ar timeout
2212elapses before a complete line of input is supplied,
2213the
2214.Ic read
2215command will return an exit status of 1 without assigning any values.
2216The
2217.Ar timeout
2218value may optionally be followed by one of
2219.Ql s ,
2220.Ql m
2221or
2222.Ql h
2223to explicitly specify seconds, minutes or hours.
2224If none is supplied,
2225.Ql s
2226is assumed.
2227.Pp
2228The
2229.Fl e
2230option exists only for backward compatibility with older scripts.
2231.It Ic readonly Oo Fl p Oc Op Ar name ...
2232Each specified
2233.Ar name
2234is marked as read only,
2235so that it cannot be subsequently modified or unset.
2236The shell allows the value of a variable to be set
2237at the same time as it is marked read only
2238by using the following form:
2239.Pp
2240.D1 Ic readonly Ar name Ns = Ns Ar value
2241.Pp
2242With no arguments the
2243.Ic readonly
2244command lists the names of all read only variables.
2245If the
2246.Fl p
2247option is specified, the read-only variables are printed as
2248.Dq Ic readonly Ar name Ns = Ns Ar value
2249lines, suitable for re-input to the shell.
2250.It Ic return Op Ar exitstatus
2251See the
2252.Sx Functions
2253subsection.
2254.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo
2255.Fl c Ar string Oc Op Fl - Ar arg ...
2256The
2257.Ic set
2258command performs three different functions:
2259.Bl -item
2260.It
2261With no arguments, it lists the values of all shell variables.
2262.It
2263If options are given,
2264either in short form or using the long
2265.Dq Fl /+o Ar longname
2266form,
2267it sets or clears the specified options as described in the section called
2268.Sx Argument List Processing .
2269.It
2270If the
2271.Dq Fl -
2272option is specified,
2273.Ic set
2274will replace the shell's positional parameters with the subsequent
2275arguments.
2276If no arguments follow the
2277.Dq Fl -
2278option,
2279all the positional parameters will be cleared,
2280which is equivalent to executing the command
2281.Dq Li "shift $#" .
2282The
2283.Dq Fl -
2284flag may be omitted when specifying arguments to be used
2285as positional replacement parameters.
2286This is not recommended,
2287because the first argument may begin with a dash
2288.Pq Ql -
2289or a plus
2290.Pq Ql + ,
2291which the
2292.Ic set
2293command will interpret as a request to enable or disable options.
2294.El
2295.It Ic setvar Ar variable value
2296Assigns the specified
2297.Ar value
2298to the specified
2299.Ar variable .
2300The
2301.Ic setvar
2302command is intended to be used in functions that
2303assign values to variables whose names are passed as parameters.
2304In general it is better to write
2305.Dq Ar variable Ns = Ns Ar value
2306rather than using
2307.Ic setvar .
2308.It Ic shift Op Ar n
2309Shift the positional parameters
2310.Ar n
2311times, or once if
2312.Ar n
2313is not specified.
2314A shift sets the value of
2315.Li $1
2316to the value of
2317.Li $2 ,
2318the value of
2319.Li $2
2320to the value of
2321.Li $3 ,
2322and so on,
2323decreasing the value of
2324.Li $#
2325by one.
2326If there are zero positional parameters, shifting does not do anything.
2327.It Ic test
2328A built-in equivalent of
2329.Xr test 1 .
2330.It Ic times
2331Print the amount of time spent executing the shell and its children.
2332The first output line shows the user and system times for the shell
2333itself, the second one contains the user and system times for the
2334children.
2335.It Ic trap Oo Ar action Oc Ar signal ...
2336.It Ic trap Fl l
2337Cause the shell to parse and execute
2338.Ar action
2339when any specified
2340.Ar signal
2341is received.
2342The signals are specified by name or number.
2343In addition, the pseudo-signal
2344.Cm EXIT
2345may be used to specify an
2346.Ar action
2347that is performed when the shell terminates.
2348The
2349.Ar action
2350may be an empty string or a dash
2351.Pq Ql - ;
2352the former causes the specified signal to be ignored
2353and the latter causes the default action to be taken.
2354Omitting the
2355.Ar action
2356is another way to request the default action, for compatibility reasons this
2357usage is not recommended though.
2358In a subshell environment,
2359the shell resets trapped (but not ignored) signals to the default action.
2360The
2361.Ic trap
2362command has no effect on signals that were ignored on entry to the shell.
2363.Pp
2364Option
2365.Fl l
2366causes the
2367.Ic trap
2368command to display a list of valid signal names.
2369.It Ic true
2370A null command that returns a 0 (true) exit value.
2371.It Ic type Op Ar name ...
2372Interpret each
2373.Ar name
2374as a command and print the resolution of the command search.
2375Possible resolutions are:
2376shell keyword, alias, special shell builtin, shell builtin, command,
2377tracked alias
2378and not found.
2379For aliases the alias expansion is printed;
2380for commands and tracked aliases
2381the complete pathname of the command is printed.
2382.It Ic ulimit Oo Fl HSabcdflmnpstuvw Oc Op Ar limit
2383Set or display resource limits (see
2384.Xr getrlimit 2 ) .
2385If
2386.Ar limit
2387is specified, the named resource will be set;
2388otherwise the current resource value will be displayed.
2389.Pp
2390If
2391.Fl H
2392is specified, the hard limits will be set or displayed.
2393While everybody is allowed to reduce a hard limit,
2394only the superuser can increase it.
2395The
2396.Fl S
2397option
2398specifies the soft limits instead.
2399When displaying limits,
2400only one of
2401.Fl S
2402or
2403.Fl H
2404can be given.
2405The default is to display the soft limits,
2406and to set both the hard and the soft limits.
2407.Pp
2408Option
2409.Fl a
2410causes the
2411.Ic ulimit
2412command to display all resources.
2413The parameter
2414.Ar limit
2415is not acceptable in this mode.
2416.Pp
2417The remaining options specify which resource value is to be
2418displayed or modified.
2419They are mutually exclusive.
2420.Bl -tag -width indent
2421.It Fl b Ar sbsize
2422The maximum size of socket buffer usage, in bytes.
2423.It Fl c Ar coredumpsize
2424The maximal size of core dump files, in 512-byte blocks.
2425.It Fl d Ar datasize
2426The maximal size of the data segment of a process, in kilobytes.
2427.It Fl f Ar filesize
2428The maximal size of a file, in 512-byte blocks.
2429.It Fl l Ar lockedmem
2430The maximal size of memory that can be locked by a process, in
2431kilobytes.
2432.It Fl m Ar memoryuse
2433The maximal resident set size of a process, in kilobytes.
2434.It Fl n Ar nofiles
2435The maximal number of descriptors that could be opened by a process.
2436.It Fl p Ar pseudoterminals
2437The maximal number of pseudo-terminals for this user ID.
2438.It Fl s Ar stacksize
2439The maximal size of the stack segment, in kilobytes.
2440.It Fl t Ar time
2441The maximal amount of CPU time to be used by each process, in seconds.
2442.It Fl u Ar userproc
2443The maximal number of simultaneous processes for this user ID.
2444.It Fl v Ar virtualmem
2445The maximal virtual size of a process, in kilobytes.
2446.It Fl w Ar swapuse
2447The maximum amount of swap space reserved or used for this user ID,
2448in kilobytes.
2449.El
2450.It Ic umask Oo Fl S Oc Op Ar mask
2451Set the file creation mask (see
2452.Xr umask 2 )
2453to the octal or symbolic (see
2454.Xr chmod 1 )
2455value specified by
2456.Ar mask .
2457If the argument is omitted, the current mask value is printed.
2458If the
2459.Fl S
2460option is specified, the output is symbolic, otherwise the output is octal.
2461.It Ic unalias Oo Fl a Oc Op Ar name ...
2462The specified alias names are removed.
2463If
2464.Fl a
2465is specified, all aliases are removed.
2466.It Ic unset Oo Fl fv Oc Ar name ...
2467The specified variables or functions are unset and unexported.
2468If the
2469.Fl v
2470option is specified or no options are given, the
2471.Ar name
2472arguments are treated as variable names.
2473If the
2474.Fl f
2475option is specified, the
2476.Ar name
2477arguments are treated as function names.
2478.It Ic wait Op Ar job
2479Wait for the specified
2480.Ar job
2481to complete and return the exit status of the last process in the
2482.Ar job .
2483If the argument is omitted, wait for all jobs to complete
2484and return an exit status of zero.
2485.El
2486.Ss Commandline Editing
2487When
2488.Nm
2489is being used interactively from a terminal, the current command
2490and the command history
2491(see
2492.Ic fc
2493in
2494.Sx Built-in Commands )
2495can be edited using
2496.Nm vi Ns -mode
2497command line editing.
2498This mode uses commands similar
2499to a subset of those described in the
2500.Xr vi 1
2501man page.
2502The command
2503.Dq Li "set -o vi"
2504(or
2505.Dq Li "set -V" )
2506enables
2507.Nm vi Ns -mode
2508editing and places
2509.Nm
2510into
2511.Nm vi
2512insert mode.
2513With
2514.Nm vi Ns -mode
2515enabled,
2516.Nm
2517can be switched between insert mode and command mode by typing
2518.Aq ESC .
2519Hitting
2520.Aq return
2521while in command mode will pass the line to the shell.
2522.Pp
2523Similarly, the
2524.Dq Li "set -o emacs"
2525(or
2526.Dq Li "set -E" )
2527command can be used to enable a subset of
2528.Nm emacs Ns -style
2529command line editing features.
2530.Sh ENVIRONMENT
2531The following environment variables affect the execution of
2532.Nm :
2533.Bl -tag -width ".Ev LANGXXXXXX"
2534.It Ev ENV
2535Initialization file for interactive shells.
2536.It Ev LANG , Ev LC_*
2537Locale settings.
2538These are inherited by children of the shell,
2539and is used in a limited manner by the shell itself.
2540.It Ev PWD
2541An absolute pathname for the current directory,
2542possibly containing symbolic links.
2543This is used and updated by the shell.
2544.It Ev TERM
2545The default terminal setting for the shell.
2546This is inherited by children of the shell, and is used in the history
2547editing modes.
2548.El
2549.Pp
2550Additionally, all environment variables are turned into shell variables
2551at startup,
2552which may affect the shell as described under
2553.Sx Special Variables .
2554.Sh EXIT STATUS
2555Errors that are detected by the shell, such as a syntax error, will
2556cause the shell to exit with a non-zero exit status.
2557If the shell is not an interactive shell, the execution of the shell
2558file will be aborted.
2559Otherwise the shell will return the exit status of the last command
2560executed, or if the
2561.Ic exit
2562builtin is used with a numeric argument, it
2563will return the argument.
2564.Sh SEE ALSO
2565.Xr builtin 1 ,
2566.Xr chsh 1 ,
2567.Xr echo 1 ,
2568.Xr ed 1 ,
2569.Xr emacs 1 ,
2570.Xr kill 1 ,
2571.Xr printf 1 ,
2572.Xr pwd 1 ,
2573.Xr test 1 ,
2574.Xr vi 1 ,
2575.Xr execve 2 ,
2576.Xr getrlimit 2 ,
2577.Xr umask 2 ,
2578.Xr editrc 5
2579.Sh HISTORY
2580A
2581.Nm
2582command, the Thompson shell, appeared in
2583.At v1 .
2584It was superseded in
2585.At v7
2586by the Bourne shell, which inherited the name
2587.Nm .
2588.Pp
2589This version of
2590.Nm
2591was rewritten in 1989 under the
2592.Bx
2593license after the Bourne shell from
2594.At V.4 .
2595.Sh AUTHORS
2596This version of
2597.Nm
2598was originally written by
2599.An Kenneth Almquist .
2600.Sh BUGS
2601The
2602.Nm
2603utility does not recognize multibyte characters other than UTF-8.
2604Splitting using
2605.Va IFS
2606and the line editing library
2607.Xr editline 3
2608do not recognize multibyte characters.
2609