“sed的”命令错误为“未知选项为s”

问题描述:

我有一个Makefile以下sed命令:“sed的”命令错误为“未知选项为s”

SNORT_OPTS=`echo -n "--disable-nls --disable-silent-rules --libdir=/usr/lib \ 
--host=x86_64-linux-gnu --build=x86_64-linux-gnu --enable-gre --enable-targetbased \ 
--enable-ppm --enable-sourcefire --enable-perfprofiling --enable-zlib \ 
--enable-non-ether-decoders" | 
sed -e 's/ +/ /'` 
sed -e "/OPTIONS :/s/:.*$$/: $$SNORT_OPTS/" -e '/OPTIONS :/a # SWE built : snort-2.9.8.2' < snort-2.9.8.2/etc/snort.conf | 
sed -f snort.conf.sed > snort-2.9.8.2/etc/snort.conf-new 

问题是,当生成文件运行它生成以下命令:

SNORT_OPTS=`echo -n "--disable-nls --disable-silent-rules --libdir=/usr/lib \ 
--host=x86_64-linux-gnu --build=x86_64-linux-gnu --enable-gre --enable-targetbased \ 
--enable-ppm --enable-sourcefire --enable-perfprofiling --enable-zlib \ 
--enable-non-ether-decoders" | 
sed -e 's/ +/ /'` 
sed -e "/OPTIONS :/s/:.*$/: $SNORT_OPTS/" -e '/OPTIONS :/a # SWE built : snort-2.9.8.2' < snort-2.9.8.2/etc/snort.conf | 
sed -f snort.conf.sed > snort-2.9.8.2/etc/snort.conf-new 

SNORT_OPTS中的双美元($)已被单美元($)取代。

这给出了一个错误: 的sed:-e表达式#,焦炭68:未知的选项,以单曲

sed命令双美元正常工作($$)。如何保证Makefile中不以“$”

+2

不应该'$$$$'变成'$$'那么? – andlrc

+0

您尝试使用'\ $ \ $'? – ClaudioM

+0

@andlrc是的工作 RootPhoenix

代替“$$”正如你已经注意到了,你能逃脱与另一美元符号美元符号:

$$hello 

当发送到/bin/sh它会将成为

$hello 

所以基本上你只需要两个逃生美元符号:

$$$$ 

会变成

$$