当前位置:网站首页>The Shell function
The Shell function
2022-08-04 03:44:00 【Drw_Dcm】
Table of Contents
First, the definition of the function
First, the definition of the function
1.
function function name{
command
} canonical usage
2.
function name() { The most common, the most concise
comnand
}
After the function is defined, it will not be executed automatically. It needs to be called. The advantage is that you can write a piece of function code as a function, and you can directly call it if you need it.error
function return value
return means to exit the function and return an exit value, which can be displayed by the $? variable in the script
Principles of use
1. The return value is taken as soon as the function ends, because the $? variable only returns the exit status code of the last command executed
2. The exit status code must be 0~255, and the value will be the remainder if it exceeds256
two, function call
The function can be called by writing the function name directly after the code block of the function definition in the script
#!/bin/bash
function fun1 { defines a function called fun1
echo "this is a function!" The function of the function body is to print "this is a function!
}
fun1 , , , , , , , , writing the function name directly will run the code in the function body
Note: 1. The function name must be unique. If one is defined first, and then defined with the same name, the second one will overwrite the first function, resulting in unexpected results, so be careful not to duplicate the name here!
2. You must define a function before calling it!
边栏推荐
- TOML configuration file format, YAML's top contender
- STM8S105K4T6------Serial port sending and receiving
- Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
- 汇编语言之栈
- 外卖店优先级
- Sfdp 超级表单开发平台 V6.0.5 正式发布
- How to systematically plan and learn software testing?
- Introduction to the memory model of the JVM
- 初识Numpy
- 4-way two-way HDMI integrated business high-definition video optical transceiver 8-way HDMI high-definition video optical transceiver
猜你喜欢
Sfdp 超级表单开发平台 V6.0.5 正式发布
说说数据治理中常见的20个问题
4-way two-way HDMI integrated business high-definition video optical transceiver 8-way HDMI high-definition video optical transceiver
docker+网桥+redis主从+哨兵模式
How to drop all tables under database in MySQL
基于Qt的目录统计QDirStat
【MD5】采用MD5+盐的加密方式完成注册用户和登录账号
Deep learning -- CNN clothing image classification, for example, discussed how to evaluate neural network model
Learn iframes and use them to solve cross-domain problems
十一种概率分布
随机推荐
Basic form validation process
2千兆光+6千兆电导轨式网管型工业级以太网交换机支持X-Ring冗余环网一键环网交换机
函数,递归以及dom简单操作
Shell 函数
出现504怎么办?由于服务器更新导致的博客报504错误[详细记录]
企业直播风起:目睹聚焦产品,微赞拥抱生态
打造一份优雅的简历
基地址:环境变量
unsafe.Pointer, pointer, reference in golang
Reproduce 20-character short domain name bypass
XSS related knowledge points
SQL interview Questions
6口全千兆二层网管型工业以太网交换机千兆2光4电光纤自愈ERPS环网交换机
本周四晚19:00知识赋能第4期直播丨OpenHarmony智能家居项目之设备控制实现
全网没有之一的JMeter 接口测试流程详解
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
网络工程师入门必懂华为认证体系,附系统学习路线分享
案例 | 重庆银行流动数据安全挑战及应对实践
SQL query String field less than 10 how to check
【项目实现】Boost搜索引擎