当前位置:网站首页>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 parameters
Four, 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
边栏推荐
猜你喜欢
随机推荐
pytorch中tensor转成图片保存
MySQL【创建和管理表】
Kubernetes 进阶训练营 控制器
30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
MySQL:索引
LeetCode50天刷题计划(Day 8—— 盛最多水的容器(23.00-1.20)
HDU 2602: Bone Collector ← 0-1背包问题
有限合伙人与普通合伙人的区别
SQL查询数据以及排序
Meeting OA project (6) --- (to-be-opened meeting, historical meeting, all meetings)
轮询和长轮询的区别
强网杯2022 pwn 赛题解析——yakagame
pwnhome 个人博客快速索引(持续更新)
MySQL【数据处理的增删改】
80篇国产数据库实操文档汇总(含TiDB、达梦、openGauss等)
2022-08-01日报:18张图,直观理解神经网络、流形和拓扑
php gui 框架 demo
LeetCode50天刷题计划(Day 7—— 字符串转换整数 (atoi) 12.20-15.20)
gconf/dconf实战编程(3)利用dconf库读写配置实战以及诸多配套工具演示
解读selenium webdriver