当前位置:网站首页>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
边栏推荐
- [rust notes] 02 ownership
- Es8 async and await learning notes
- Debug debugging - Visual Studio 2022
- Monotonic stack -84 The largest rectangle in the histogram
- How to delete CSDN after sending a wrong blog? How to operate quickly
- Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
- Log4j2 vulnerability recurrence and analysis
- JS ternary operator - learning notes (with cases)
- [rust notes] 13 iterator (Part 1)
- PHP function date (), y-m-d h:i:s in English case
猜你喜欢
JS non Boolean operation - learning notes
Deep parsing (picture and text) JVM garbage collector (II)
Unity editor expansion - scrolling list
Concurrent programming (VI) ABA problems and solutions under CAS
Unity interactive water ripple post-treatment
我们有个共同的名字,XX工
PHP uses foreach to get a value in a two-dimensional associative array (with instances)
第一个Servlet
Redux - learning notes
[rust notes] 02 ownership
随机推荐
【Rust 笔记】13-迭代器(上)
DOM 渲染系统(render mount patch)响应式系统
[concurrent programming] atomic operation CAS
Unity editor expansion - scrolling list
Character pyramid
[rust notes] 06 package and module
【Rust笔记】02-所有权
Deep parsing (picture and text) JVM garbage collector (II)
createjs easeljs
UE4 source code reading_ Bone model and animation system_ Animation process
数位统计DP AcWing 338. 计数问题
ES6 promise learning notes
【Rust 笔记】11-实用特型
【Rust 笔记】07-结构体
Annotations simplify configuration and loading at startup
Tree DP acwing 285 A dance without a boss
Es8 async and await learning notes
Apache startup failed phpstudy Apache startup failed
Unity interactive water ripple post-treatment
Divide candy (circular queue)