builtin

Bash return

Ends a function or sourced file with status n; if omitted, uses the last command status. It does not return a string.

Formal Syntax & Structure

bash syntaxbash
return [n]

Parameters & Attributes

NameTypeDescription
nintegerExit status; use 0–255.

Return Value

exit status

Ends a function or sourced file with status n; if omitted, uses the last command status. It does not return a string.

Working Example

Example Snippetbash
check() {  if [[ $# -eq 1 && -n $1 ]]; then return 0; fi  return 2}check goodprintf 'valid=%s\n' "$?"check ''printf 'invalid=%s\n' "$?"
Bash Reference