9.3.22 return command (returns from a function or an external script)
Syntax
return [n]
Description
This command returns from a function or an external script, then continues processing in the calling function. Note that this command exits the shell if it is executed at a location other than from within a function or an external script.
Regardless of the value of the return code, this command terminates normally or with an error on the basis of whether the command syntax is valid.
If no argument is specified, the command terminates normally with the return code from the command that executed last as the return code. If it executes with a valid numeric value specified as the argument, it terminates normally. If it executes with an invalid value specified as the argument, such as non-numeric characters, it terminates with an error. When this command terminates with an error, it returns 1 as the return code.
Arguments
- n ~<unsigned integer>((0 to 255))
Specifies the return code. When this argument is omitted, the command returns with the return code from the command that executed last. If you specify 256 or a greater value for this argument, the command terminates normally with a return code that is the remainder from dividing the specified value by 256. If you specify a negative value, the command terminates normally with a return code that is the two's complement of the specified value.
Return codes
Return code |
Meaning |
---|---|
0 to 255 |
Normal termination
|
1 |
Error termination
|
Notes
You can specify for n a negative value or a value that is greater than 255, but we recommend that you specify in JP1/Advanced Shell a value in the range of 0 to 255.
If the command syntax of this special built-in command is invalid, it exits the shell that is executing the command.
When executing the return command in a separate process, such as the & operator and a command substitution, also see the notes provided in 5.1.7 Execution as a separate process.
Example
Return with return code 2 from a function or external script and continue processing in the calling function.
return 2