当前位置:网站首页>Shell basic function writing
Shell basic function writing
2022-08-01 15:32:00 【Test_the_rookie】
One, why do you need to use functions
Because the shell does not have the concept of modules and classes, when we have a large number of scripts that need to be executed in order to implement a function, for the convenience of operation, these codes will be put together and executed by calling a specific name..Improve the reuse rate of scripts and optimize the code structure.Second, grammar
[function] method name(){Script to be executedUsually, [function is omitted or not written]}
Three, pass parameters
3.1shell only supports 9 parameters by default. $1 and $2 represent the first parameter respectively. You can use shift to pass more parameters.
3.2, $# represents the number of incoming parameters, excluding $03.3, $$ indicates the pid of the current script execution3.4, $! The last running pid in the backgroundAdditional understanding:The difference between $a and $*:When passing parameters between functions, "$a" will not break up the passed parameters; $* will break up the passed parametersFour, function call
4.1. Function call: When calling a function, you can directly call it by entering the function name4.2, parameter passing: add a space after the function name, and then keep up with the parameters that need to be passed
Five, debug
1. Provide parameters at the beginning of the script #! /bin/sh -x2.-v means print to standard error output during execution3.-n will read the script once, but will not execute the script, it will check for syntax errors-------------------- Self-discipline is not easy, I hope you can stick to it边栏推荐
- 动态模型中嵌入静态模型实践
- 长江欧拉生态创新中心成立,武汉数字经济再添坚实底座
- pynlpir更新license Error: unable to fetch newest license解决方案
- 网站2D看板娘收集的可用的模型
- Distributed database problem (1): data partition
- 2.8K 120Hz touch dual-screen blessing Lingyao X dual-screen Pro 2022 makes the office without fear of imagination
- 2022年5月20日最全摸鱼游戏导航
- 产品力无提升的雷克萨斯新款ES ,为何敢于涨价?
- Grid布局 容器属性(一) `grid-template`系列属性
- Stock Strategy 02 | Technology Timing + Industry Factors + Market Value Rotation
猜你喜欢

Stock Strategy 02 | Technology Timing + Industry Factors + Market Value Rotation

LeetCode50天刷题计划(Day 11—— 最接近的三数之和(8.40-10.00)

Grid布局 容器属性(一) `grid-template`系列属性

2.8K 120Hz触控双屏加持 灵耀X 双屏Pro 2022让办公无惧想象

预定义和自定义

会议OA项目(六)--- (待开会议、历史会议、所有会议)

gconf/dconf实战编程(2)利用gconf库读写配置实战以及诸多配套工具演示

长江欧拉生态创新中心成立,武汉数字经济再添坚实底座

反序列化漏洞详解

美国弗吉尼亚大学、微软 | Active Data Pattern Extraction Attacks on Generative Language Models(对生成语言模型的主动数据模式提取攻击)
随机推荐
COPU 陆首群教授在 openEuler 社区首批高级顾问聘任仪式上发言
MySQL【创建和管理表】
kubelet node pressure eviction
urlopen error errno111(英雄联盟报错error)
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
Grid布局 容器属性(一) `grid-template`系列属性
Kubernetes 进阶训练营 控制器
"Find nearby shops" | Geohash+MySQL realizes geographic location filtering
LeetCode50天刷题计划(Day 10—— 三数之和(20.50-22.40)
Bloom filter bloom
兆骑科创科创赛事平台,创业赛事活动路演,线上直播路演
0-1背包问题的一维数组优化解析
可观测性就是对“监控”的包装?
SyntaxHighlighter带来的字符转义问题
SQL query data and sorting
WPF如何自定义隐藏下拉框选项
视频传输协议(常用的视频协议)
Timezone setting in MySQL
xmind2testcase:高效的测试用例导出工具
美国弗吉尼亚大学、微软 | Active Data Pattern Extraction Attacks on Generative Language Models(对生成语言模型的主动数据模式提取攻击)