当前位置:网站首页>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边栏推荐
猜你喜欢

The soul asks: How does MySQL solve phantom reads?

leetcode:33. 搜索旋转排序数组

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

【论文笔记】MiniSeg: An Extremely Minimum Network for Efficient COVID-19 Segmentation

MySQL:索引

Meeting OA project (6) --- (to-be-opened meeting, historical meeting, all meetings)

30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?

反序列化漏洞详解

JSON数据转换总结(VIP典藏版)

String comparison size in MySQL (date string comparison problem)
随机推荐
预定义和自定义
尾牙宴是什么
南京科技大学、中国电子科技第28研究所等联合|MLRIP: Pre-training a military language representation model with informative factual knowledge and professional knowledge base(预训练具有丰富事实知识和专业知识库的军事语言表示模型)
美国弗吉尼亚大学、微软 | Active Data Pattern Extraction Attacks on Generative Language Models(对生成语言模型的主动数据模式提取攻击)
长江欧拉生态创新中心成立,武汉数字经济再添坚实底座
flink -redis sink 可以sink 到集群吗?
what is tail tooth feast
可观测性就是对“监控”的包装?
kubelet节点压力驱逐
游戏元宇宙发展趋势展望分析
给网站增加离开页面改变网站标题效果
【论文笔记】MiniSeg: An Extremely Minimum Network for Efficient COVID-19 Segmentation
设计专业第一台笔记本 华硕灵耀Pro16 2022 新品首发超值入手
bug- 切换代理服务器与同步 bug
LeetCode50天刷题计划(Day 7—— 字符串转换整数 (atoi) 12.20-15.20)
gconf/dconf实战编程(2)利用gconf库读写配置实战以及诸多配套工具演示
选择合适的 DevOps 工具,从理解 DevOps 开始
Row locks in MySQL
MySQL中的时区设置
透过现象看本质,如何针对用户做好需求分析