2023-07-05 10:53:12 +02:00
|
|
|
# The exit builtin command
|
|
|
|
|
|
|
|
## Synopsis
|
|
|
|
|
|
|
|
exit [N]
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
The `exit` command terminates the current shell (or script).
|
|
|
|
|
|
|
|
If `N` is given, the return code to the parent process is set to `N`. If
|
|
|
|
not, the returned status the the status of the most recently executed
|
|
|
|
command (i.e. `$?`).
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
A [trap](../../commands/builtin/trap.md) on `EXIT` is executed before the shell
|
2023-07-05 10:53:12 +02:00
|
|
|
exits, except the executed `exit` command is part of an already running
|
|
|
|
trap.
|
|
|
|
|
|
|
|
### Options
|
|
|
|
|
|
|
|
There are no options.
|
|
|
|
|
|
|
|
### Exit status
|
|
|
|
|
2024-03-30 20:09:26 +01:00
|
|
|
Naturally, you can't ask for the exit status from within the shell that
|
2023-07-05 10:53:12 +02:00
|
|
|
executed the `exit` command, because the shell exits.
|
|
|
|
|
|
|
|
Status Reason
|
|
|
|
-------- ----------------------------------------------------------------------------
|
|
|
|
255 invalid (e.g. non-numeric) argument - this staus is returned to the parent
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Exit the shell and explicitely set its exit status
|
|
|
|
|
|
|
|
exit 3
|
|
|
|
|
|
|
|
## Portability considerations
|
|
|
|
|
|
|
|
- if `N` is specified, but its value is not between 0 and 255
|
|
|
|
inclusively, the exit status is undefined.
|
|
|
|
|
|
|
|
## See also
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
- [The trap builtin command](../../commands/builtin/trap.md)
|
2024-04-02 23:19:23 +02:00
|
|
|
- [The exit status](../../dict/exit_status.md)
|