return
return
In Linux, the return
command is used to exit a shell function or script. It is a built-in command that is supported by all Linux distributions.
The return
command is used in the following syntax:
The exit status
is an integer that is used to indicate the success or failure of the shell function or script. The exit status can be any number from 0 to 255.
For example, the following shell function will print the message "Hello, world!" and then return the exit status 0:
The following script will print the message "This is a script" and then return the exit status 1:
The return
command is a useful tool for controlling the flow of execution in a shell function or script. It can be used to exit a function or script early, or to return an exit status to the calling function or script.
Here are some additional things to note about the return
command:
The
return
command can only be used inside a shell function or script.The
return
command cannot be used in the interactive shell.The
return
command will always exit the shell function or script, even if it is nested inside another shell function or script.The
return
command can be used to return a non-zero exit status to the calling function or script. This can be useful for debugging or for signaling an error condition.
The return
command is a versatile tool that can be used to control the flow of execution in a shell function or script. It is a built-in command that is supported by all Linux distributions.
help
Last updated