return
发表于|更新于|Linux
|总字数:191|阅读时长:1分钟|浏览量:
return
从函数中退出并返回数值。
概要
1 | return [n] |
主要用途
- 使得shell函数退出并返回数值,如果没有指定n的值,则默认为函数最后一条命令执行的返回状态。
参数
n(可选):整数。
返回值
返回值为你指定的参数n的值,如果你指定的参数大于255或小于0,那么会通过加或减256的方式使得返回值总是处于0到255之间。
在函数外执行return语句会返回失败。
例子
1 | #!/usr/bin/env bash |
注意
- 该命令是bash内建命令,相关的帮助信息请查看
help命令。
文章作者: Estom
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Estom的博客!
相关推荐

2021-09-02
29-Context
原文链接 视频链接:147-148 在 Go http 包的 Server 中,每一个请求都有一个对应的 goroutine 去处理。请求处理函数通常会启动额外的 goroutine 用来访问后端服务,比如数据库和 RPC 服务。用来处理一个请求的 goroutine 通常需要访问一些与请求特定的数据,比如终端用户的身份认证信息、验证相关的 token、请求的截止时间。 当一个请求被取消或超时时,所有用来处理该请求的 goroutine 都应该迅速退出,然后系统才能释放这些 goroutine 占用的资源。 1. 为什么需要Context1.1. 基本示例1234567891011121314151617181920212223242526272829package mainimport ( "fmt" "sync" "time")var wg sync.WaitGroup// 初始的例子func worker() { for { fmt.Println("worker") ...

2021-03-09
4 函数
>函数 >>函数定义:完成特定功能的一个语句组,这组语句可以作为一个单位使用,并且给他求个名字,通过函数名执行 >>语法: [python] viewplaincopy <span style=”font-size:18px;”> def print_sum(start, stop): “”” to calculate the sum from start to stop “”” result = 0 for i in range(star, stop + 1): result += i print ‘sum is’, result</span> 第一行定义了一个函数,关键字 def ,函数名 print_sum,函数参数start, stop >>函数调用 [python] viewplaincopy <span style=”font-size:18px;”>print_sum(a, b)</span>...

2021-03-05
7 IO
IO IO关系图 IO 类的继承关系图 目录 输入输出流iostream 文件输入输出流fstream 字符串输入输出流sstream 0 stream基础知识 IO对象没有拷贝或赋值 管理IO的状态 继承自basic_ios和basic_ios_base基类 用来记录stream可能出现的状态。 使用iostate对象来记录和管理io的状态 >> <<流运算符(流函数)会返回io的运行状态,如果成功,则会返回true,否则返回false 1234567891011121314151617181920212223#include<iostream>using namespace std;int main(){ //IO state test int a{3}; cin>>a; auto old_state = cin.rdstate();//返回s当前的状态 cout<<old_state<<endl;//输出状态 co...

2021-09-02
4-流程控制
4 流程控制和运算符Go 语言中常用的流程控制有 if 和 for。而 switch 和 goto 主要是为了简化代码、降低重复代码而生的结构,属于扩展类的流程控制。 4.1 if 语句4.1.1 if 语句的基本格式1234567if 表达式1 { 分支1} else if 表达式2 { 分支2} else { 分支3} 4.1.2 if 的特殊写法12345678// 此处声明的变量 score 只在 if 语句中有效if score := 65; score >= 90 { fmt.Println("A")} else if score > 75 { fmt.Println("B")} else { fmt.Println("C")} 4.2 for 语句go 语言中所有的循环类型都可以使用 for 关键字来完成。 4.2.1 for 基本格式123for 初始语句; 条件表达式;...

2020-09-25
11数学运算
数学函数(Mathematical functions)三角函数 method description sin(x, /[, out, where, casting, order, …]) 正弦函数, element-wise. cos(x, /[, out, where, casting, order, …]) 余弦函数 element-wise. tan(x, /[, out, where, casting, order, …]) 正切函数, element-wise. arcsin(x, /[, out, where, casting, order, …]) 反正弦函数, element-wise. arccos(x, /[, out, where, casting, order, …]) 反余弦函数, element-wise. arctan(x, /[, out, where, casting, order, …]) 反正切函数, element-wise. hypot(x1,...

2020-09-26
colorbar_basics
颜色条通过指定可映射对象(此处为imshow返回的 AxesImage )和要将颜色条附加到的轴来使用 colorbar。 1234567891011121314151617181920212223242526272829303132333435import numpy as npimport matplotlib.pyplot as plt# setup some generic dataN = 37x, y = np.mgrid[:N, :N]Z = (np.cos(x*0.2) + np.sin(y*0.3))# mask out the negative and positive values, respectivelyZpos = np.ma.masked_less(Z, 0)Zneg = np.ma.masked_greater(Z, 0)fig, (ax1, ax2, ax3) = plt.subplots(figsize=(13, 3), ncols=3)# plot just the positive data and save the# color "...




