The exit built-in causes the shell process to exit.

Syntax

  • exit [-f] [exit_status]

Description

The exit built-in causes the current shell (or subshell) process to exit.

If an interactive shell has a stopped job, the shell prints a warning message and refuses to exit. To force the shell to exit regardless, specify the -f (--force) option or execute the built-in twice in a row.

If an EXIT trap has been set, the shell executes the trap before exiting.

Options

-f
--force

Suppress warnings that would prevent the shell from exiting.

Operands

exit_status

A non-negative integer that will be the exit status of the exiting shell.

If this operand is omitted, the exit status of the shell will be that of the last command executed before the exit built-in (but, if the built-in is executed during a trap, the exit status will be that of the last command before the trap is entered).

If the exit status is larger than 384, the shell may terminate itself with a signal instead of exiting with the specified exit status. See Termination of the shell for details.

Exit status

Because the built-in causes the shell to exit, there is no exit status of the built-in.

As an exception, if the shell refused to exit, the exit status of the built-in is non-zero.

Notes

The exit built-in is a special built-in.

The POSIX standard defines no options for the exit built-in; the built-in accepts no options in the POSIXly-correct mode.

Exit status values greater than 255 are non-portable extensions.

If the built-in is executed during an EXIT trap, the shell just exits without executing the trap again. If exit_status was not specified, the exit status of the shell is what the exit status would be if the trap had not been set. See also Termination of the shell.