当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
SQL查询语句之查询数据
what is tail tooth feast
LeetCode50天刷题计划(Day 10—— 三数之和(20.50-22.40)
Spark: Cluster Computing with Working Sets
利用UIRecorder做页面元素巡检
“查找附近的商铺”|Geohash+MySQL实现地理位置筛选
只知道SQL数据库?又一国产数据库语言诞生了
大神们,ODPS用的是MySQL吗?
第十三章 手动创建 REST 服务(一)
Chapter 13 Manually create a REST service (1)
Distributed database problem (1): data partition
Next-ViT学习笔记
CodeForces 570D Tree Requests
math.pow()函数用法[通俗易懂]
分布式数据库难题(一):数据分区
MySQL【数据处理的增删改】
预定义和自定义
在网站页脚增加几只戏水的小鱼
2022年5月20日最全摸鱼游戏导航
lombok builder重写