Bash - Return - (Function|Shell) exit

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

1 - About

Return is a bash builtin function that causes to update the exit status specified by n.

Return is intended to be used only for signaling errors, not for returning the results of function.

Advertising

3 - Syntax

return [n]

If used:

  • inside a function. Return value specified by n. If n is omitted, the return status is that of the last command executed in the function body.
  • outside a function,
    • during execution of a script by the . (source) command, it causes the shell to stop executing that script and return either n or the exit status of the last command executed within the script as the exit status of the script.
    • not during execution of a script by . (source), the return status is false.

Any command associated with the RETURN trap is executed before execution resumes after the function or script.