A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/return-command-in-linux-with-examples/ below:

return command in Linux with examples

return command in Linux with examples

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.

Syntax
return [N]

where,

Basic return Command Example

Note: echo $? is used to display the last return status.

Option used with the return command

return --help : It displays help information.

Key Differences Between return and exit

return: 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.

Conclusion

The 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