1EXIT(1P)                   POSIX Programmer's Manual                  EXIT(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       exit — cause the shell to exit
13

SYNOPSIS

15       exit [n]
16

DESCRIPTION

18       The exit utility shall cause the shell to exit from its current  execu‐
19       tion environment with the exit status specified by the unsigned decimal
20       integer n.  If the current execution environment is a subshell environ‐
21       ment, the shell shall exit from the subshell environment with the spec‐
22       ified exit status and continue in the environment from which that  sub‐
23       shell  environment was invoked; otherwise, the shell utility shall ter‐
24       minate with the specified exit status. If n is specified, but its value
25       is not between 0 and 255 inclusively, the exit status is undefined.
26
27       A  trap  on  EXIT shall be executed before the shell terminates, except
28       when the exit utility is invoked in that trap itself, in which case the
29       shell shall exit immediately.
30

OPTIONS

32       None.
33

OPERANDS

35       See the DESCRIPTION.
36

STDIN

38       Not used.
39

INPUT FILES

41       None.
42

ENVIRONMENT VARIABLES

44       None.
45

ASYNCHRONOUS EVENTS

47       Default.
48

STDOUT

50       Not used.
51

STDERR

53       The standard error shall be used only for diagnostic messages.
54

OUTPUT FILES

56       None.
57

EXTENDED DESCRIPTION

59       None.
60

EXIT STATUS

62       The  exit  status shall be n, if specified, except that the behavior is
63       unspecified if n is not an unsigned decimal integer or is greater  than
64       255.  Otherwise,  the value shall be the exit value of the last command
65       executed, or zero if no command was executed. When exit is executed  in
66       a  trap  action,  the last command is considered to be the command that
67       executed immediately preceding the trap action.
68

CONSEQUENCES OF ERRORS

70       Default.
71
72       The following sections are informative.
73

APPLICATION USAGE

75       None.
76

EXAMPLES

78       Exit with a true value:
79
80
81           exit 0
82
83       Exit with a false value:
84
85
86           exit 1
87
88       Propagate error handling from within a subshell:
89
90
91           (
92               command1 || exit 1
93               command2 || exit 1
94               exec command3
95           ) > outputfile || exit 1
96           echo "outputfile created successfully"
97

RATIONALE

99       As explained in other sections, certain exit status  values  have  been
100       reserved  for  special uses and should be used by applications only for
101       those purposes:
102
103        126    A file to be executed was found, but it was not  an  executable
104               utility.
105
106        127    A utility to be executed was not found.
107
108       >128    A command was interrupted by a signal.
109
110       The  behavior  of exit when given an invalid argument or unknown option
111       is unspecified, because of differing practices in the various  histori‐
112       cal  implementations. A value larger than 255 might be truncated by the
113       shell, and be unavailable even to a parent process that  uses  waitid()
114       to get the full exit value. It is recommended that implementations that
115       detect any usage error should cause a non-zero exit status (or, if  the
116       shell  is  interactive and the error does not cause the shell to abort,
117       store a non-zero value in "$?"), but even this was  not  done  histori‐
118       cally in all shells.
119

FUTURE DIRECTIONS

121       None.
122

SEE ALSO

124       Section 2.14, Special Built-In Utilities
125
127       Portions  of  this text are reprinted and reproduced in electronic form
128       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
129       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
130       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
131       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
132       event of any discrepancy between this version and the original IEEE and
133       The  Open Group Standard, the original IEEE and The Open Group Standard
134       is the referee document. The original Standard can be  obtained  online
135       at http://www.opengroup.org/unix/online.html .
136
137       Any  typographical  or  formatting  errors that appear in this page are
138       most likely to have been introduced during the conversion of the source
139       files  to  man page format. To report such errors, see https://www.ker
140       nel.org/doc/man-pages/reporting_bugs.html .
141
142
143
144IEEE/The Open Group                  2017                             EXIT(1P)
Impressum