当前位置:网站首页>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
边栏推荐
- Get the link behind? Parameter value after question mark
- [concurrent programming] thread foundation and sharing between threads
- Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)
- First Servlet
- Parameters of convolutional neural network
- 22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
- Message pack in C deserializes array objects
- 注解简化配置与启动时加载
- UE4 source code reading_ Bone model and animation system_ Animation process
- How to delete CSDN after sending a wrong blog? How to operate quickly
猜你喜欢

Deeply understand the underlying data structure of MySQL index

Six dimensional space (C language)

22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制

Too many open files solution

Life cycle of Servlet

Graphics_ Games101/202 learning notes

注解简化配置与启动时加载

Binary tree sorting (C language, char type)

Complex character + number pyramid

Unity interactive water ripple post-treatment
随机推荐
Parameters of convolutional neural network
Mortgage Calculator
php public private protected
Graphics_ Learnopongl learning notes
【Rust笔记】02-所有权
20220630 learning clock in
Divide candy (circular queue)
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
TP5 multi condition sorting
Notes and bugs generated during the use of h:i:s and y-m-d
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
Es8 async and await learning notes
Log4j2 vulnerability recurrence and analysis
【Rust 笔记】13-迭代器(上)
Too many open files solution
数据库原理期末复习
JS non Boolean operation - learning notes
Deep parsing (picture and text) JVM garbage collector (II)
Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
注解简化配置与启动时加载