当前位置:网站首页>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
边栏推荐
- 22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
- Deep parsing (picture and text) JVM garbage collector (II)
- Apache startup failed phpstudy Apache startup failed
- php public private protected
- [concurrent programming] thread foundation and sharing between threads
- Find the combination number acwing 886 Find the combination number II
- Baidu editor ueeditor changes style
- ES6 promise learning notes
- [MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
- DOM render mount patch responsive system
猜你喜欢
[RPC] RPC remote procedure call
[concurrent programming] thread foundation and sharing between threads
Alibaba canal actual combat
状态压缩DP AcWing 291. 蒙德里安的梦想
20220630 learning clock in
Query XML documents with XPath
JS non Boolean operation - learning notes
数位统计DP AcWing 338. 计数问题
UE4 source code reading_ Bone model and animation system_ Animation process
Annotations simplify configuration and loading at startup
随机推荐
[concurrent programming] atomic operation CAS
Log4j2 vulnerability recurrence and analysis
Eating fruit
Collection interface
C language student management system based on linked list, super detailed
【Rust笔记】05-错误处理
Monotonic stack -503 Next bigger Element II
高斯消元 AcWing 883. 高斯消元解线性方程组
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
20220630学习打卡
[rust notes] 13 iterator (Part 1)
状态压缩DP AcWing 291. 蒙德里安的梦想
Binary tree sorting (C language, int type)
How to deal with the core task delay caused by insufficient data warehouse resources
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
单调栈-84. 柱状图中最大的矩形
Common DOS commands
Try to reprint an article about CSDN reprint
PHP function date (), y-m-d h:i:s in English case
TP5 order multi condition sort