TrumanWong

return

Exit from the function and return a value.

Summary

return [n]

The main purpose

  • Causes the shell function to exit and return a value. If the value of n is not specified, it defaults to the return status of the last command executed by the function.

Parameters

n (optional): integer.

return value

The return value is the value of the parameter n you specify. If the parameter you specify is greater than 255 or less than 0, then the return value will always be between 0 and 255 by adding or subtracting 256.

Executing the return statement outside the function will return failure.

example

#!/usr/bin/env bash
# Define a function with a return value greater than 255
example() {
   return 259
}
#Execute function
example
# show 3
echo $?

Notice

  1. This command is a built-in bash command. For related help information, please see the help command.