Bash 将sed与${parameter}一起使用 问题
如何在Bash 将sed与${parameter}一起使用 问题,bash,sed,edit,Bash,Sed,Edit,如何在sed编辑字符串中使用变量 例子 文件statement.txt就是这个句子 我喜欢我的宠物鸟 给定一个变量${myPet},我们如何使用sed将bird替换为${myPet}中的值 什么不起作用 sed-ie's/bird/${myPet}/g'statement.txt 结果是 我喜欢我的宠物${myPet} ”单引号不会扩展shell变量的值,因此需要在此处使用“双引号 myPet="your_value" sed -ie "s/bird/${myPet}/g" statement.
sed
编辑字符串中使用变量
例子
文件statement.txt
就是这个句子
我喜欢我的宠物鸟
给定一个变量${myPet}
,我们如何使用sed
将bird
替换为${myPet}
中的值
什么不起作用
sed-ie's/bird/${myPet}/g'statement.txt
结果是
我喜欢我的宠物${myPet}
”
单引号不会扩展shell变量的值,因此需要在此处使用“
双引号
myPet="your_value"
sed -ie "s/bird/${myPet}/g" statement.txt