HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

return — Exit a function. Can exit out of a script if run with `source`. See also: `exit`. More information:

Submitted by: @import:tldr-pages··
0
Viewed 0 times
commandexitcanfunctionclioutreturn

Problem

How to use the return command: Exit a function. Can exit out of a script if run with source. See also: exit. More information: <https://www.gnu.org/software/bash/manual/bash.html#index-return>.

Solution

return — Exit a function. Can exit out of a script if run with source. See also: exit. More information: <https://www.gnu.org/software/bash/manual/bash.html#index-return>.

Exit a function prematurely:
{{func_name}}() { {{echo "This is reached"}}; return; {{echo "This is not"}}; }


Specify the function's return value:
{{func_name}}() { return {{exit_code}}; }

Code Snippets

Exit a function prematurely

{{func_name}}() { {{echo "This is reached"}}; return; {{echo "This is not"}}; }

Specify the function's return value

{{func_name}}() { return {{exit_code}}; }

Context

tldr-pages: common/return

Revisions (0)

No revisions yet.