当前位置:网站首页>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!
边栏推荐
- SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropri
- How to read the resources files in the directory path?
- Oracle与Postgresql在PLSQL内事务回滚的重大差异
- Sfdp 超级表单开发平台 V6.0.5 正式发布
- 三分建设,七分管理!产品、系统、组织三管齐下节能降耗
- 基于Qt的目录统计QDirStat
- 马尔可夫链
- 嵌入式数据库开发编程MySQL(全)
- Polygon zkEVM网络节点
- 高效IO模型
猜你喜欢
This Thursday evening at 19:00, the fourth live broadcast of knowledge empowerment丨The realization of equipment control of OpenHarmony smart home project
Postgresql source code (66) insert on conflict grammar introduction and kernel execution process analysis
仿牛客论坛项目梳理
SQL query String field less than 10 how to check
The general SQL injection flow (sample attached)
【源码】使用深度学习训练一个游戏
基地址:环境变量
高效IO模型
八年软件测试工程师带你了解-测试岗进阶之路
Polygon zkEVM network node
随机推荐
Exclude_reserved_words 排除关键字
How many ways do you know about communication between multiple threads?
初识Numpy
2 Gigabit Optical + 6 Gigabit Electric Rail Type Managed Industrial Ethernet Switch Supports X-Ring Redundant Ring One-key Ring Switch
一个属于程序员的七夕节!
There are too many systems, how to realize multi-account interworking?
new Date converts strings into date formats Compatible with IE, how ie8 converts strings into date formats through new Date, how to replace strings in js, and explain the replace() method in detail
汇编语言之栈
使用serve搭建本地服务器
2022 Hangzhou Electric Power Multi-School League Game 5 Solution
PL/SQL Some Advanced Fundamental
《nlp入门+实战:第八章:使用Pytorch实现手写数字识别》
Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析
2022杭电多校联赛第五场 题解
数组相关 内容 解析
自定义通用分页标签01
Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
Polygon zkEVM network node
基本表单验证流程
数据治理平台项目总结和分析