Create return.md

新增文档
This commit is contained in:
ZhuangZhu-74 2019-08-08 10:40:15 +08:00 committed by GitHub
parent 44dd34078d
commit dd30af8111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

45
command/return.md Normal file
View File

@ -0,0 +1,45 @@
return
===
从函数中退出并返回数值。
## 概要
```shell
return [n]
```
## 主要用途
- 使得shell函数退出并返回数值如果没有指定n的值则默认为函数最后一条命令执行的返回状态。
## 参数
n可选整数。
## 返回值
返回值为你指定的参数n的值如果你指定的参数大于255或小于0那么会通过加或减256的方式使得返回值总是处于0到255之间。
在函数外执行return语句会返回失败。
## 例子
```shell
#!/usr/bin/env bash
# 定义一个返回值大于255的函数
example() {
return 259
}
# 执行函数
example
# 显示3
echo $?
```
### 注意
1. 该命令是bash内建命令相关的帮助信息请查看`help`命令。
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->