日期:2014-05-16  浏览次数:20607 次

sed 变量替换问题
str=‘dsdd s’

sed 's/meta/'$str'/g' ./temp/html5.html >./temp/html5h.html
发现这样替换不了

sed 's/meta/dsdd s/g' ./temp/html5.html >./temp/html5h.html

而这样可以替换
这是为什么 我要如何做到第一中替换了
------解决方案--------------------
sed "s/meta/$str/g"
单引号不会解释变量
------解决方案--------------------
str=ds dds这句赋值就有问题,应该加引号
str="ds dds"
sed "s/meta/$str/g" ./temp/html5.html >./temp/html5h.html


引用:
@zaghost

str=ds dds
sed "s/meta/$str/g" ./temp/html5.html >./temp/html5h.html
还是替换失败 ./temp/html5h.html 内容为空

如果将str=ds dds 去掉空格就可以替换 加上就不能
但是我直接sed "s/meta/ds dds/g"  这样写就可以替换成功 ……