当前位置:网站首页>Rech8.0 learning days 12 rh134
Rech8.0 learning days 12 rh134
2020-11-07 16:49:02 【The shadow of rebellion 1992】
Writing room BASH Script
bash shell The first line of the script begins with : #!/bin/bash
Created shell Script , Need to use chmod Command to add executable permissions , There are also willing to be with chown Command combination changes the file ownership of the script . Grant execute permission only to the target user of the script .
Quote special characters , Three tools to cancel or escape special meanings : The backslash (\)、 Single quotation marks ('')、 Double quotes ("").
The backslash escape character removes the special meaning of the single character immediately following it . Example :
When you need to escape multiple characters in a text string , You can use single quotation marks (''). A single quotation mark retains the literal meaning of all characters it contains .:
Using double quotation marks can prevent generic matching and shell Expand , But it still allows command and variable substitution . Variable substitution is conceptually the same as command substitution
echo Command in shell Scripts are widely used to display information and error messages .
shell The cycle in
bash Of for Loop structure Use the grammar .
for VARIABLE in LTST; do
COMMAND VARIABLE
done
The lower case part is fixed .VARIABLE Is a variable name. ,COMMAND VARIABLE A command block that represents a reference variable .
Use exit code in scripts
Use exit command . When the script encounters exit On command , The script exits immediately and does not process the rest of the script .
It can be an integer parameter ( Optional ,0-255 Between , Indicates the exit code ) To execute exit command . The exit code is returned to the parent process , Store it in ? variable , Can pass $? Visit .
Conditional structure
if/then The structural grammar is as follows :
also if/then/else structure :
also if/then/elif/then/else structure
Use regular expressions to match text in command output
vim、grep and less All commands can use regular expressions .
The simplest perfect match , That is, the characters in the regular expression match the type and order of the data being searched , It's a perfect match .
Match the beginning and end of a line , Search at the beginning of the line , Use the caret (^). Search at the end of the line , Use the dollar sign ($).
Regular expressions use periods (.) Or point (.) To match any single character other than a newline character .c.t Include the search for c Add any single character and t String .
c[aou]t Will match : With c start , Follow behind a or o or u, And then there was t, namely cat、cot、cut.
A mechanism that is often used with wildcards . The multiple is applied to the previous character in the expression , One of the more common multiples is the asterisk (*).
c*t, Match anything with c start , Followed by zero or more characters , Finally t Data at the end .
Another type of multiple will indicate the expected number of preceding characters in the pattern .‘c.\{2\}t’ Is an example of using display multiples , It matches with c start , Followed by any string , Finally t Any words at the end .
Regular expressions
Options | describe |
. | Period (.) Match any single character . |
? | The front item is optional , And match at most once . |
* | The previous items will match zero or more times . |
+ | The previous items will match one or more times . |
{n} | The front item just matches n Time . |
{n,} | The front item matches n Times or more . |
{,m} | The front items match at most m Time . |
{n,m} | The front items at least match n Time , But not more than m Time . |
[:alnum:] | Alphanumeric character :‘[:alpha:]’ and ‘[:digit:]’; stay 'C' Language environment and ASCII In character encoding , It is equivalent to ‘[0-9A-Za-z]’ |
[:alpha:] | Alphabetic character :‘[:lower:]’ and '[:upper:]'; stay 'C' Language environment and ASCII In character encoding , It is equivalent to ‘[A-Za-z]’. |
[:blank:] | Blank character : Spaces and tabs . |
[:cntrl:] | Control characters . stay ASCII in , These characters correspond to octal code 000 To 037 and 177(DEL). In other character sets , They are equivalent characters . |
[;digit;] | Numbers :0 1 2 3 4 5 6 7 8 9 . |
[;graph;] | Image characters :‘[:alnum:]’ and '[:punct:]'. |
[:lower:] | Lowercase letters ; stay ”C“ Language environment and ASCII In character encoding , It corresponds to a b c d e f g h i j k l m n o p q r s t u v w x y z. |
[:print:] | Printable characters :‘[:alnum:]’、'[:punct:]' And Spaces . |
[:punct:] | Punctuation ; stay ”C“ Language environment and ASCII In character encoding , It corresponds to !” # $ %&'()*+,-./:;<=>[email protected][\]^'{|}~. |
[:space:] | Space character ; |
[:upper:] | Capital |
[:xdigit:] | 16 Hexadecimal Numbers : 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f . |
\b | Matches the empty string on both sides of the word . |
\B | Matches an empty string in the middle of a word . |
\< | Matches the empty string at the beginning of the word . |
\> | Matches the empty string at the end of the word . |
\w | Match word components |
\W | Match non word components |
\s | Match spaces |
\S | Match non spaces . |
Use grep The command matches the regular expression
The vertical line operator (|),grep Commands can be used with other commands . Example :
common grep List of options
Options | function |
-i | Use the provided regular expression , But it doesn't force case sensitivity . |
-v | Show only lines that do not contain regular expression matches . |
-r | Apply a data search that recursively matches a regular expression to a set of files or directories . |
-A number | Shows the number of lines after a regular expression match . |
-B number | Shows the number of lines before a regular expression match . |
-e | You can provide multiple regular expressions , And will be associated with logic OR Use it together . |
版权声明
本文为[The shadow of rebellion 1992]所创,转载请带上原文链接,感谢
边栏推荐
- 小白量化投资交易入门课(python入门金融分析)
- 寻找性能更优秀的动态 Getter 和 Setter 方案
- Looking for better dynamic getter and setter solutions
- VsCode之Markdown插件
- Markdown plug-in of vscode
- C++ STL容器篇
- C + + STL container
- Looking for a small immutable dictionary with better performance
- Atlas vs datahub vs Amundsen
- 数据治理方案技术调研 Atlas VS Datahub VS Amundsen
猜你喜欢
-
Atlas vs datahub vs Amundsen
-
Performance testing and tuning practice based on fabric
-
Apache DolphinScheduler(海豚调度) - 1.3 系列核心表结构剖析
-
CSDN博主排名更新,看看原来的前1000名博主现在的排名如何
-
Comparison and selection of mongodb Mongoose
-
Python:PyCharm选择性忽略PEP8警告
-
Analysis of Apache dolphin scheduler-1.3 series core table structure
-
CSDN blogger ranking update to see how the original top 1000 bloggers now rank
-
Alipay
-
Python: pychar selectively ignores pep8 warnings
随机推荐
- 2020年11月程序员工资统计,平均14327元
- 2020年10月中国编程语言排行榜
- 2020年10月程序员工资统计,平均14459元
- 2020年9月中国编程语言排行榜
- 2020年8月中国编程语言排行榜
- 2020年7月中国编程语言排行榜
- 2020年7月程序员工资统计,平均14357元,又跌了,扎心
- 2020年3月全国程序员工资统计,平均工资13820元
- 2020年2月全国程序员工资统计,平均工资13716元
- 2020年1月全国程序员工资统计,平均工资13632元。
- 2020年一线城市程序员工资大调查
- Lambda, functional interface, stream
- Property table collection of JVM virtual machine class file
- Field table collection of JVM virtual machine class file
- In November 2020, the average wage of programmers is 14327 yuan
- Chinese programming language rankings in October 2020
- In October 2020, the average salary of programmers is 14459 yuan
- Chinese programming language rankings in September 2020
- In September 2020, the average wage of programmers is 14469 yuan
- In August 2020, the average wage of programmers is 14401 yuan, and the decline has stopped
- Chinese programming language rankings in August 2020
- Chinese programming language rankings in July 2020
- In July 2020, the average wage of programmers is 14357 yuan, which falls again
- In March 2020, the national programmer salary statistics, the average wage of 13820 yuan
- In February 2020, the national programmer salary statistics, the average wage of 13716 yuan
- In January 2020, the national programmer salary statistics, the average wage of 13632 yuan.
- A survey of programmer's salary in first tier cities in 2020
- Handle Unicode, byte order, UTF at one time-*
- SQL basic syntax, very complete recommended collection (Oriental Dream)
- Introduction to shell programming (4) text processing
- 实时语义分割
- Real time semantic segmentation
- Uniapp unlimited tree structure components, multi-choice components, support search, unlimited bread crumb type navigation
- HaaS 100硬件规格
- Haas 100 hardware specifications
- 简易签名组件zm-sign
- Simple signature component ZM sign
- . net 5 ORM eight practical skills dry goods - sqlsugar ORM
- . net 5 ORM eight practical skills dry goods - sqlsugar ORM
- C language I blog assignment 06