使用变量时sed替换不工作 [英] Sed replacement not working when using variables

查看:98
本文介绍了使用变量时sed替换不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些奇怪的尝试与SED来替换字符串时发生。这工作:

something strange is happening when trying to replace string with sed. This works :

find /home/loni/config -type f -exec sed -i 's/some_pattern/replacement/g' {} \;

所以,它的工作原理,当我手动输入字符串。但在低于更替的情况下不会发生:

So it works when I manually type the strings. But in the case below replacement doesn't occur :

find /home/loni/config -type f -exec sed -i 's/${PATTERN}/${REPLACEMENT}/g' {} \;

当我赞同这两个变量模式和替换他们有正确的价值观。

When I echo these two variables PATTERN and REPLACEMENT they have the correct values.

我想用我的config目录下的所有文件替换字符串替换模式字符串的所有出现。

I'm trying to replace all occurences of pattern string with replacement string in all files in my config directory.

推荐答案

尝试

find /home/loni/config -type f -exec sed -i "s/${PATTERN}/${REPLACEMENT}/g" {} \;

来代替。在'行情不扩展变量。

instead. The ' quotes don't expand variables.

这篇关于使用变量时sed替换不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆