#Bash 的 return 命令
return [N]
功能
Shell 函数或脚本返回。
类型
Bash 内置命令。
参数
N- 函数(或脚本)的返回值为N;如果省略此参数,则以最后一个命令的返回值作为函数(或脚本)的返回值
#示例
#!/bin/bash
func() {
return 10 # 返回 10
}
func # 调用 func
echo $? # 查看返回值
运行结果:
10
#手册
return: return [n]
Return from a shell function.
Causes a function or sourced script to exit with the return value
specified by N. If N is omitted, the return status is that of the
last command executed within the function or script.
Exit Status:
Returns N, or failure if the shell is not executing a function or script.