return builtin
The builtin that ends a function and sets its exit status, a number from 0 to 255, not a text value.
In more detail
To hand back text, print it and capture it with command substitution; use the status for a yes or no answer so the function can sit directly in an if. Without a number, return uses the status of the last command.
Related terms
- shell function — A named group of commands, defined as name() { ...; }, that you then run like any other command.
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- command substitution — Running a command inside $( ) and replacing it with that command's standard output, as in today=$(date).
Taught in
- Functions, local And declare — Bash Scripting & Command Line Automation
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation