【问题标题】:Using sed from makefile to replace a string with a $ in it [duplicate]使用makefile中的sed将字符串替换为$ [重复]
【发布时间】:2017-12-24 17:42:56
【问题描述】:

我有一个简单的 sed 替换文本文件:

sed -i 's/Temp_3/$t0/g' ./somefile.txt

当我在 bash 脚本中使用它时,一切工作正常。 但是,如果我尝试使用 ma​​kefile 中的同一行, $t (可能)扩展为空字符串 (makefile 中没有名为 t 的变量)和 将 Temp_3 替换为 0。解决此问题的最佳方法是什么? 谢谢!

【问题讨论】:

  • 不清楚,请提供更多信息。

标签: sed makefile


【解决方案1】:

发生的事情是 make 首先进行它的替换, 在你的情况下$t 什么都没有,然后运行命令。 您可以或应该;)通过如下更改命令来规避此问题:将$ 更改为$$; make 会将双 $ 符号替换为单个符号。

sed -i 's/Temp_3/$$t0/g' ./somefile.txt

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 1970-01-01
    • 2019-10-14
    • 2012-03-08
    • 2014-09-17
    • 2021-12-18
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    相关资源
    最近更新 更多