当前位置:网站首页>Shell built-in string substitution
Shell built-in string substitution
2022-06-13 04:53:00 【qq_ thirty-nine million two hundred and eighty thousand seven h】
shell Variable assignment syntax :
Usage rule | explain |
---|---|
Single quotation marks | What you see is what you get , That is, all contents within single quotation marks will be output as is , Or it is described as what you see in single quotation marks and what will be output , This is called strong reference |
Double quotes ( Default ) | Output everything in double quotes ; If there is an order in the content ( It's going to lead you down )、 Variable 、 Special escape characters, etc , It's going to put variables first 、 command 、 The escape character parses the result , And then output the final content , Recommended , This is called weak reference |
No quotes | assignment , If there are spaces in the variable content , The assignment will be incomplete . And when you output content , The string containing spaces will be output as a whole ; If there is an order in the content ( It's going to lead you down )、 Variable etc. , Then the variable will be 、 The command parses the result , And then output the final content ; If there are special characters such as spaces in the string , You may not be able to completely output , Therefore, double quotation marks are required to replace the case without quotation marks , In particular, double quotation marks are added when assigning values to variables . Generally continuous string 、 Numbers 、 The path can be assigned and output without any quotation marks , But it's better to use it |
The quotation marks | Generally used to reference commands , When executed, the command will be executed , amount to S0, Both assignment and output use “ Cause an order to |
Examples of use without quotation marks :
Assignment without quotation marks , Contain Spaces :
take world Interpreted as a variable
Assignment without quotation marks , Variables contain spaces :
Normal output :
Use summary without quotation marks :
assignment , Do not insert special characters such as spaces .
shell Built in String Syntax :
Writing shell The program , String related operations are often involved . There are many command statements , Such as awk,sed Can do a variety of string operations . in fact shell Built in a series of operation symbols , Similar results can be achieved , Using the internal operator will omit the time to start the external program , So the speed will be very fast . If the built-in operators can do it , Use built-in... First .
quote :shell String built-in common operations
1 Read string value
expression | meaning |
${var} | Variable var The original value |
${var-default} | var No return is declared default, But it doesn't change. var Value |
${var:-default} | var If it is not declared or its value is null, return default, But it doesn't change. var Value |
${var=default} | var No declaration to return default, And will var Is set to default |
${var:=default} | var If it is not declared or its value is null, return default, And will var Is set to default |
${var+other} | var Declared return other, But it doesn't change. var Value |
${var:+other} | var Declared and not empty return other, But it doesn't change. var Value |
${var?err_msg} | var Not declared , The message is err_msg Send to standard error output |
${var:?err_msg} | var Not declared or empty , The message is err_msg Send to standard error output |
${!varprefix*} | Before matching, all are marked with varprefix Variables declared at the beginning |
${[email protected]} | Before matching, all are marked with varprefix Variables declared at the beginning |
2 String manipulation
expression | meaning |
${#string} | string The length of |
${string:position} | stay string in , From the position position Start extracting substrings |
${string:position:length} | stay string in , From the position position Start extraction with a length of $length The string of |
${string#substring} | Dependent variable string The beginning of , Delete the shortest match substring The string of |
${string##substring} | Dependent variable string The beginning of , Delete the longest match substring The string of |
${string%substring} | Dependent variable string Ending , Delete the shortest match substring The string of |
${string%%substring} | Dependent variable string Ending , Delete the longest match substring The string of |
${string/substring/replacement} | Use replacement, To replace the first matching substring |
${string//substring/replacement} | Use replacement, Replace all matching substring |
${string/#substring/replacement} | hypothesis string The prefixes match substring, Then use replacement To replace the matching substring |
${string/%substring/replacement} | hypothesis string The suffix matches substring, Then use replacement To replace the matching substring |
explain :"substring” It can be a regular expression |
shell Examples of built-in strings :
1. String substitution
${string/substring/replacement}
string It's a shell Variable (${} The rules )
边栏推荐
- Develop go using vscode
- Explain the differences and usage scenarios between created and mounted
- C#获取WebService接口的所有可调用方法[WebMethod]
- 用navicat将mysql数据转化为postgresql
- 2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
- 2022 ICML | Pocket2Mol: Efficient Molecular Sampling Based on 3D Protein Pockets
- 2022 oxidation process operation certificate examination question bank and simulation examination
- 【JS解决】leedcode 200. 岛屿数量
- Logical point
- Serial communication learning
猜你喜欢
QT client development -- driver loading problem of connecting to MySQL database
Solution to sudden font change in word document editing
2022 ICLR | CONTRASTIVE LEARNING OF IMAGE- AND STRUCTURE BASED REPRESENTATIONS IN DRUG DISCOVERY
[JS solution] leedcode 200 Number of islands
C disk lossless move file
Configuration used by automatic teaching evaluation script
2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
Leetcode game 297 (20220612)
josephus problem
Section 2 - branch and loop statements
随机推荐
C#获取WebService接口的所有可调用方法[WebMethod]
2021TPAMI/图像处理:Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
Win8.1和Win10各自的优势
Colab tutorial (super detailed version) and colab pro/pro+ evaluation
[untitled]
RuoYi-Cloud启动教程(手把手图文)
用navicat将mysql数据转化为postgresql
Infinite cycle scrolling code Alibaba international station store decoration code base map scrolling black translucent display effect custom content decoration code full screen display
Advanced C - Section 2 - pointers
Analysis on the usage, response and global delivery of provide/inject
Go/golang connection to database
2022氯化工艺操作证考试题库及模拟考试
Optocoupler working principle function electric parameter application circuit
CMB's written test -- data analysis
利用Javeswingjdbc基於mvc設計系統
2022 question bank and answers for operation certificate examination of safety production management personnel in road transport enterprises
How to use redis
Embedded hardware: electronic components (1) resistance capacitance inductance
2022年氧化工艺操作证考试题库及模拟考试
你的一对一会议效率低下,你可以这么做!