当前位置:网站首页>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!
边栏推荐
- 复现20字符短域名绕过
- Postgresql source code (66) insert on conflict grammar introduction and kernel execution process analysis
- 一个属于程序员的七夕节!
- JVM的内存模型简介
- 三分建设,七分管理!产品、系统、组织三管齐下节能降耗
- 外卖店优先级
- 【MD5】采用MD5+盐的加密方式完成注册用户和登录账号
- 元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
- Implementing a server-side message active push solution based on SSE
- unsafe.Pointer, pointer, reference in golang
猜你喜欢
企业直播风起:目睹聚焦产品,微赞拥抱生态
软件测试如何系统规划学习呢?
Architecture of the actual combat camp module three operations
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
马尔可夫链
基于Qt的目录统计QDirStat
y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)
KingbaseES数据库启动失败,报“内存段超过可用内存”
如果禁用了安全启动,GNOME 就会发出警告
深度学习——以CNN服装图像分类为例,探讨怎样评价神经网络模型
随机推荐
Brush esp8266-01 s firmware steps
MySQL查询优化与调优
A Preliminary Study of RSS Subscription to WeChat Official Account-feed43
学会iframe并用其解决跨域问题
Gigabit 2 X light 8 electricity management industrial Ethernet switches WEB management - a key Ring Ring net switch
How many ways do you know about communication between multiple threads?
kingbaseES V8R2/R3 表在指定表空间,为何显示为默认表空间?
数据安全峰会2022 | 美创DSM获颁“数据安全产品能力验证计划”评测证书
类如何只能静态分配和只能动态分配
逻辑漏洞----其他类型
深度学习——以CNN服装图像分类为例,探讨怎样评价神经网络模型
基于Qt的目录统计QDirStat
《nlp入门+实战:第八章:使用Pytorch实现手写数字识别》
Introduction to the memory model of the JVM
【MD5】采用MD5+盐的加密方式完成注册用户和登录账号
基于 SSE 实现服务端消息主动推送解决方案
Shell 函数
Mockito单元测试
STM8S project creation (STVD creation) --- use COSMIC to create a C language project
MRS: Introduction to the use of Alluxio