【发布时间】:2013-06-25 16:40:28
【问题描述】:
我想在 etter.conf 文件中取消注释第 168 行。该命令在终端中运行正常,但在 perl 中尝试时出现错误。
system ("sed -i '168s/.*/redir_command_on = "iptables -t nat -A PREROUTING -i %iface -p tcp --dport %port -j REDIRECT --to-port %rport"/' /etc/etter.conf");
错误是:
Bareword found where operator expected at ./attack.pl line 135, near
""sed -i '168s'/.*'/redir_command_on = "iptables"
我认为这与特殊字符和转义有关。
【问题讨论】:
-
您需要转义嵌套引号。 Perl 认为 iptables 应该是可变的。
-
命令中的双引号终止了 perl 字符串。
-
您向
sed发起攻击有什么原因吗? Perl 完全能够自行更新文件。 -
您甚至可以在 Perl 中进行“就地”编辑,完全没有必要使用 sed。