当前位置:网站首页>Shell_ 07_ Functions and regular expressions
Shell_ 07_ Functions and regular expressions
2022-07-06 16:51:00 【Coke loving w】
Shell_07_ Functions and regular expressions
function
function : Script code block , You can call... From anywhere by function name
1) Functions are divided into function library functions and user-defined functions , And the function name is unique ;
2) The function to be called must be created ;
3) When the function is finished , Will return a status code
// Select the return status code or return Specified value of the command
Custom function
function: Create functions in the script file
Command format :
function Function name (){
Procedures section
}
(1)retun The command can end the function in advance , And return the specified status code
1) The range of directly specified values is :0~255( If more than 255, Then find the remainder 256)
(2) The default variable for each function is :
1)$0 Represents the function name
2)$1 Represents the first function parameter 、$2 Represents the second function parameter ( And so on )
(3) adopt local command , You can specify local variables inside the function
1)Shell Variables created in the script , Default to global variable
(4) If the defined function is repeated , Then the latter function will overwrite the former function
Such as : establish show123.sh The script file will one、two、three Convert to 1、2、3
1) To write show123.sh Script files 
2) call show123.sh Script files

Such as : adopt result The command returns the status code
1) To write test25.sh Script files ;
2) call test25.sh Script files 
Such as : Create local variables in functions
1) To write test31.sh Script files 
2) call test31.sh Script files 
Regular expressions
Pattern template (Pattern Template): Filter the required data in the data stream through regular expressions
Regular expressions : Operate on strings in behavioral units
1) Regular expressions are divided into : Basic regular expressions 、 Extended regular expression
2) Different languages may lead to different results for the same regular expression
3) Regular symbols in gawk In command , It needs to be added at the beginning and end “/” Symbol
Matching is divided into : Greedy matching ( Default )、 Non greedy matching
1) Greedy matching : When multiple results match successfully , Select the one with the most successful matching data ;
2) Non greedy matching : When multiple results match successfully , Select the one with the least successful matching data ;
// Add “?” Symbol , That is, non greedy matching
POSIX Basic regular expressions (Basic Regular Expression,BRE):
| Basic regular symbols | analysis |
|---|---|
| ^ | meaning : At the beginning of the line Example : Find a line beginning with # The line of , And the output demonstration :grep ‘^#’ test.txt |
| $ | meaning : At the end of the line Example : Find a line ending with # The line of , And the output demonstration :grep ‘#$’ test.txt |
| . | meaning : There must be an arbitrary character for Example : Find out what contains eve、eae、e e The line of , And the output ( A space is also a character ) demonstration :grep ‘e.e’ test.txt |
| * | meaning : Represents the subsequent occurrence of the previous character 0 Times and any number of times Example : Find out what contains es、ess、essss The line of , And the output demonstration :grep ‘ess*’ test.txt |
| \ | meaning : Remove the special meaning of special symbols Example : Find out what contains ^ The line of , And the output demonstration :grep \^ test.txt |
| [ ] | meaning : Find all lines of example characters Example : Find out what contains aay、afy、aly The line of , And the output demonstration :grep ‘a[alf]y’ test.txt |
| meaning : Find lines within the character range Example : Find lines with uppercase letters demonstration :grep ‘[A-Z]’ test.txt | |
| { } | meaning : lookup n To m Lines of characters in a range Example : lookup g To d contains 2 To 5 individual o The line of , And the output demonstration :grep ‘go\{2,5\}d’ test.txt |
| meaning : Find out what contains n Character lines Example : lookup g To d contains 3 individual o The line of , And the output demonstration :grep ‘go\{3\}d’ test.txt | |
| meaning : Find at least n Character lines Example : lookup g To d contains 3 individual o The above line , And the output demonstration :grep ‘go\{3,\}d’ test.txt | |
| [^] | meaning : Represents not containing a character Example : Find a file that does not contain test The line of , And the output demonstration :grep ‘[^test]’ test.txt |
POSIX Extended regular expression (Extended Regular Expression,ERE):
| Extended regular symbol | analysis |
|---|---|
| + | meaning : Represents the subsequent occurrence of the previous character 1 Times and any number of times Example : Find out what contains esd、essd、essssd The line of , And the output demonstration :grep +E ‘es+d’ test.txt |
| ? | meaning : Represents the subsequent occurrence of the previous character 0 Secondary sum 1 Time Example : Find out what contains gd、god The line of , And the output demonstration :grep +E ‘go?d’ test.txt |
| | | meaning : For or on behalf of Example : Find out what contains gd or god or good The line of , And the output demonstration :grep +E ‘gd | god | good’ test.txt |
| ( ) | meaning : Represents the combination of multiple characters Example : Find out what contains glad and good The line of , And the output demonstration :grep +E ‘g(la | oo)d’ test.txt |
| ( )+ | meaning : Represents multiple repeated combined characters Example : Find out what contains A123123123123C The line of , And the output demonstration :grep +E ‘A(123)+C’ test.txt |
边栏推荐
- Research Report on market supply and demand and strategy of China's tetraacetylethylenediamine (TAED) industry
- Spark的RDD(弹性分布式数据集)返回大结果集
- 7-7 ring the stupid bell
- Li Kou leetcode 280 weekly match
- Market trend report, technical innovation and market forecast of tabletop dishwashers in China
- I'm "fixing movies" in ByteDance
- ~85 transition
- 提交Spark应用的若干问题记录(sparklauncher with cluster deploy mode)
- Solve the single thread scheduling problem of intel12 generation core CPU (II)
- LeetCode 1584. Minimum cost of connecting all points
猜你喜欢
![Saw local status change event StatusChangeEvent [timestamp=1644048792587, current=DOWN, previous=UP]](/img/e6/c53ad67ead1793a2acb93c26e8d377.jpg)
Saw local status change event StatusChangeEvent [timestamp=1644048792587, current=DOWN, previous=UP]

Detailed explanation of FLV format

~83 form introduction

Mp4 format details

Submit several problem records of spark application (sparklauncher with cluster deploy mode)

Chapter 5 namenode and secondarynamenode

字节跳动2022校招研发提前批宣讲会,同学们最关心的10个问题

The concept of spark independent cluster worker and executor

Record the error reason: terminate called after throwing an instance

MP4格式详解
随机推荐
[unsolved] 7-15 shout mountain
Introduction to microservices
LeetCode 1638. Count the number of substrings with only one character difference
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
~68 Icon Font introduction
「博士毕业一年,我拿下 ACL Best Paper」
第6章 DataNode
Solve the single thread scheduling problem of intel12 generation core CPU (II)
腾讯面试算法题
LeetCode1556. Thousand separated number
这116名学生,用3天时间复刻了字节跳动内部真实技术项目
Error: case label `15 'not within a switch statement
JS time function Daquan detailed explanation ----- AHAO blog
第5章 消费者组详解
How to configure hosts when setting up Eureka
Chapter 5 yarn resource scheduler
~70 row high
Tencent interview algorithm question
字节跳动2022校招研发提前批宣讲会,同学们最关心的10个问题
LeetCode 1560. The sector with the most passes on the circular track