当前位置:网站首页>Using variables in sed command
Using variables in sed command
2022-07-03 08:53:00 【Xiaoping is extraordinary】
stay sed There are three ways to use variables in commands
The way 1: Use single quotes , Use single quotation marks at variables + Double quotation marks enclose variables
#!/bin/bash
name=tomas
sed -i 's/rose/'"${name}"'/g' b.txt
The way 2: Use double quotes , Variables can be directly referenced
#!/bin/bash
name=tomas
sed -i "s/rose/${name}/g" name.txt
The way 3: Use single quotes , Variables are directly referenced , But it needs to pass eval Execute this sed command .eval Will be right behind Shell Command to scan twice , If after the first scan ,Shell Command is a common command , Then execute this command ; If Shell Commands are indirect references that contain variables , Ensure the semantics of indirect reference
#!/bin/bash
name=tomas
eval sed -i 's/rose/${name}/g' name.txt
边栏推荐
- Unity notes 1
- producer consumer problem
- 树形DP AcWing 285. 没有上司的舞会
- UE4 source code reading_ Bone model and animation system_ Animation process
- createjs easeljs
- Unity editor expansion - controls, layouts
- 樹形DP AcWing 285. 沒有上司的舞會
- Unity interactive water ripple post-treatment
- JS ternary operator - learning notes (with cases)
- 单调栈-84. 柱状图中最大的矩形
猜你喜欢

Dom4j遍历和更新XML

Find the combination number acwing 886 Find the combination number II

Try to reprint an article about CSDN reprint
![[concurrent programming] thread foundation and sharing between threads](/img/26/60fbfe65b186867a3b1cb58d481226.jpg)
[concurrent programming] thread foundation and sharing between threads

Unity editor expansion - draw lines

Redux - learning notes

On the setting of global variable position in C language

数位统计DP AcWing 338. 计数问题
![[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q](/img/76/6561a78b7f883a0e75a53e037153c3.jpg)
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q

Log4j2 vulnerability recurrence and analysis
随机推荐
Life cycle of Servlet
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
数位统计DP AcWing 338. 计数问题
PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
On the difference and connection between find and select in TP5 framework
Unity Editor Extension - Outline
Parameters of convolutional neural network
PHP function date (), y-m-d h:i:s in English case
Unity Editor Extension - event handling
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
cres
Sending and receiving of request parameters
[concurrent programming] Table hopping and blocking queue
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
Talking about: is the HashSet set ordered or disordered /hashset set unique, why can we store elements with the same content
Use of sort command in shell
Message pack in C deserializes array objects
TP5 order multi condition sort
On the setting of global variable position in C language