Last Updated : 24 Sep, 2024
return command is used to exit from a shell function. It takes a parameter [N], if N is mentioned then it returns [N] and if N is not mentioned then it returns the status of the last command executed within the function or script. N can only be a numeric value.
The return command is especially useful when writing complex shell scripts, as it provides a mechanism for error handling and decision-making based on the status codes returned by various functions or commands.
Syntaxreturn [N]
where,
Option used with the return commandNote:
echo $?
is used to display the last return status.
return --help : It displays help information.
Key Differences Between return and exitreturn: Used to exit from a function and return a status code. It is only applicable inside functions.
exit: Terminates the entire script and can be used anywhere within the script.
ConclusionThe return command helps in shell scripting that allows you to control the flow of your scripts by exiting functions and specifying return codes. By using return, you can make your scripts more robust and able to handle different conditions and errors efficiently.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4