EXIT(1P)
π PROLOG π
okay bestie, real talk before we get into it: this page is part of the POSIX Programmer's Manual. the Linux version of this whole situation might be different (so like, go check the matching Linux manual page for the deets on how Linux actually behaves), or honestly it might not even be implemented on Linux at all. π
β¨ NAME β¨
exit β make the shell dip out. that's it. that's the whole job. π
πΈ SYNOPSIS πΈ
exit [n]
π¦ DESCRIPTION π¦
okay so the exit utility makes the shell leave its current execution environment, and it takes the exit status you give it β that's the unsigned decimal integer n. π
here's the tea tho:
- if the current execution environment is a subshell environment, the shell exits from that subshell environment with the exit status you specified, and then it keeps going in the environment that invoked that subshell environment. so like, the subshell leaves, the party continues. π
- otherwise, the shell utility itself terminates, with the exit status you specified. bye forever. π
and if n is specified but its value is not between 0 and 255 inclusively, the exit status is undefined. like, nobody knows what happens. it's giving chaos. π
also! a trap on EXIT gets executed before the shell terminates β with one exception: if the exit utility is invoked in that trap itself, then the shell exits immediately. no extra steps. periodt. β¨
π OPTIONS π
None. literally zero. nothing to see here. π
π OPERANDS π
go look at the DESCRIPTION. it's all in there, babe. π«Ά
π STDIN π
Not used. untouched. unbothered. β¨
π INPUT FILES π
None. π
π§ ENVIRONMENT VARIABLES π§
None. nope. zero. πΈ
β ASYNCHRONOUS EVENTS β
Default. π¦
π STDOUT π
Not used. she's not talking to stdout today. π
π₯ STDERR π₯
standard error shall be used only for diagnostic messages. that's its one job. π
π OUTPUT FILES π
None. π
πΈ EXTENDED DESCRIPTION πΈ
None. π
β¨ EXIT STATUS β¨
okay so the exit status shall be n, if you specified it β with the caveat that the behavior is unspecified if n is not an unsigned decimal integer, or if it's greater than 255. unspecified!! π
otherwise? the value shall be the exit value of the last command that was executed, or zero if no command was executed. cute.
and one more lil detail bestie: when exit is executed in a trap action, the "last command" is considered to be the command that executed immediately preceding the trap action. π
π¦ CONSEQUENCES OF ERRORS π¦
Default. π
heads up: the following sections are informative. (iykyk) π«
π APPLICATION USAGE π
None. π
π EXAMPLES π
exit with a true value:
exit 0
exit with a false value:
exit 1
propagate error handling from within a subshell:
(
command1 || exit 1
command2 || exit 1
exec command3
) > outputfile || exit 1
echo "outputfile created successfully"
slay. π«Ά
π RATIONALE π
so, like explained in other sections, certain exit status values are reserved for special uses, and applications should only use them for those exact purposes. respect the reserved list, bestie:
126β a file to be executed was found, but it was not an executable utility.127β a utility to be executed was not found.>128β a command was interrupted by a signal.
now the messy part: the behavior of exit when you hand it an invalid argument or an unknown option is unspecified, because all the historical implementations did their own thing. not iconic, just facts. π
a value larger than 255 might get truncated by the shell, and then it's unavailable even to a parent process that uses waitid() to get the full exit value. so like, the full value? gone. π
it is recommended that implementations which detect any usage error should cause a non-zero exit status β or, if the shell is interactive and the error doesn't cause the shell to abort, store a non-zero value in "$?". but even that wasn't done historically in all shells. so yeah. π
π FUTURE DIRECTIONS π
None. π
β SEE ALSO β
- Section 2.14, Special Built-In Utilities
π 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. (it's the final boss. π)
The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
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 .
okay that's the whole page bestie, we ate and left no crumbs π«Άβ¨ this was IEEE/The Open Group, 2017, signing off π ππ¦
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms