summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2017/man1p/exit.1p
blob: d8d05ccc18f680196e8079ad25cbfd68de7319b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'\" et
.TH EXIT "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
exit
\(em cause the shell to exit
.SH SYNOPSIS
.LP
.nf
exit \fB[\fIn\fB]\fR
.fi
.SH DESCRIPTION
The
.IR exit
utility shall cause the shell to exit from its current execution
environment with the exit status specified by the unsigned decimal integer
.IR n .
If the current execution environment is a subshell environment, the
shell shall exit from the subshell environment with the specified exit
status and continue in the environment from which that subshell
environment was invoked; otherwise, the shell utility shall terminate
with the specified exit status. If
.IR n
is specified, but its value is not between 0 and 255 inclusively, the
exit status is undefined.
.P
A
.IR trap
on
.BR EXIT
shall be executed before the shell terminates, except when the
.IR exit
utility is invoked in that
.IR trap
itself, in which case the shell shall exit immediately.
.SH OPTIONS
None.
.SH OPERANDS
See the DESCRIPTION.
.SH STDIN
Not used.
.SH "INPUT FILES"
None.
.SH "ENVIRONMENT VARIABLES"
None.
.SH "ASYNCHRONOUS EVENTS"
Default.
.SH STDOUT
Not used.
.SH STDERR
The standard error shall be used only for diagnostic messages.
.SH "OUTPUT FILES"
None.
.SH "EXTENDED DESCRIPTION"
None.
.SH "EXIT STATUS"
The exit status shall be
.IR n ,
if specified, except that the behavior is unspecified if
.IR n
is not an unsigned decimal integer or is greater than 255. Otherwise,
the value shall be the exit value of the last command executed, or
zero if no command was executed. When
.IR exit
is executed in a
.IR trap
action, the last command is considered to be the command that executed
immediately preceding the
.IR trap
action.
.SH "CONSEQUENCES OF ERRORS"
Default.
.LP
.IR "The following sections are informative."
.SH "APPLICATION USAGE"
None.
.SH EXAMPLES
Exit with a
.IR true
value:
.sp
.RS 4
.nf

exit 0
.fi
.P
.RE
.P
Exit with a
.IR false
value:
.sp
.RS 4
.nf

exit 1
.fi
.P
.RE
.P
Propagate error handling from within a subshell:
.sp
.RS 4
.nf

(
    command1 || exit 1
    command2 || exit 1
    exec command3
) > outputfile || exit 1
echo "outputfile created successfully"
.fi
.P
.RE
.SH "RATIONALE"
As explained in other sections, certain exit status values have been
reserved for special uses and should be used by applications only for
those purposes:
.IP "\0126" 8
A file to be executed was found, but it was not an executable utility.
.IP "\0127" 8
A utility to be executed was not found.
.IP >128 8
A command was interrupted by a signal.
.P
The behavior of
.IR exit
when given an invalid argument or unknown option is unspecified,
because of differing practices in the various historical
implementations. A value larger than 255 might be truncated by the
shell, and be unavailable even to a parent process that uses
\fIwaitid\fR()
to get the full exit value. It is recommended that implementations
that detect any usage error should cause a non-zero exit status (or,
if the shell is interactive and the error does not cause the shell to
abort, store a non-zero value in
.BR \(dq$?\(dq ),
but even this was not done historically in all shells.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 2.14" ", " "Special Built-In Utilities"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .