Bash - Exit Builtin command

> Procedural Languages > Bash Shell and (Unix|Linux) Utilities (XCU)

1 - About

exit is a builtin command and cause the shell to exit with a given exit status.

Advertising

3 - Syntax

exit [n]

If n is omitted,the exit status is that of the last command executed.

4 - Post function

A function can be called on a EXIT before the shell terminates.

Example: by calling the exit function, the following finish function will run thanks to the registration of the function via the trap utility

#!/bin/bash
function finish {
  # Your cleanup code here
}
trap finish EXIT

5 - Documentation / Reference