为什么SED忽略文件变量? [英] Why does sed ignore the file variable?

查看:167
本文介绍了为什么SED忽略文件变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我直接放置在文件路径名到code,它运行正常 - 更换这两个START- / ENDTAGs之间的文件中的code。但是,如果我用一个变量而不是文件路径名,它要么删除整个部分进行更换或完全忽略它。

If I place the file path name directly into the code, it runs as expected - replacing the code within the file between those two START-/ENDTAGs. But, if I use a variable instead of that file path name, it will either delete the entire section to be replaced or ignore it completely.

#!/bin/bash

CF_HTMLHEAD=$(cat ./cf_templates/cf_HtmlHead.txt)
...
sed '
    '"$ENDTAG"' r $CF_HTMLHEAD
    '"$STARTTAG"','"$ENDTAG"' d
' -i $TARGETDIR

我试过使用'$ CF_HTMLHEAD','$ CF_HTMLHEAD和$ CF_HTMLHEAD
和改变变量定义,本身: CF_HTMLHEAD = $(...)',=$(...),两线之间的所有组合的我能想到的。

I've tried using '"$CF_HTMLHEAD"' , '$CF_HTMLHEAD' and "$CF_HTMLHEAD" and changing the variable definition, itself: CF_HTMLHEAD='$(...)' , ="$(...)" , and all combinations between the two lines that I could think of.

任何线索,SED如何读取文件的输入变量??

Any clues as to how sed can read a file input variable??

推荐答案

根据穆鲁的和伊坦赖斯纳的见解,这个问题是变量的声明。

Based on Muru's and Etan Reisner's insight, the issue was in the variable declaration.

CF_HTMLHEAD=./cf_templates/cf_HtmlHead.txt

有一次,我脱下了和中,code跑了我。谢谢大家!

Once I took off the ' and ", the code ran for me. Thanks, everyone!

这篇关于为什么SED忽略文件变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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