从 Makefile 内部使用 Perl 进行字符串替换
我正在尝试用 Makefile 中的 perl 替换文件中的字符串。
InstallTo = $(PWD)/WebTest
BuildApache:
mkdir -p WebTest
cd Source/httpd; ./configure --prefix=$(InstallTo) --exec-prefix=$(InstallTo)
cd Source/httpd; make; make install
cd $(InstallTo)/conf; perl -pi -e 's/ServerRoot \"$(InstallTo)\"/ServerRoot/g' httpd.conf
cd $(InstallTo)/conf; cp -f httpd.conf httpd.conf.orig
我不确定我到底在做什么,我只是尝试根据我在网上找到的东西修改 perl 行。我认为它把事情搞砸了,但我对 Perl 的了解还不够多,无法修复它。
I'm trying to replace a string, inside of a file, with perl from inside a Makefile.
InstallTo = $(PWD)/WebTest
BuildApache:
mkdir -p WebTest
cd Source/httpd; ./configure --prefix=$(InstallTo) --exec-prefix=$(InstallTo)
cd Source/httpd; make; make install
cd $(InstallTo)/conf; perl -pi -e 's/ServerRoot \"$(InstallTo)\"/ServerRoot/g' httpd.conf
cd $(InstallTo)/conf; cp -f httpd.conf httpd.conf.orig
I'm not sure exactly what I'm doing though, I've just tried to modify the perl line from something I found on the net. I think its the \" thats messing things up but I don't know enough about Perl to fix it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想尝试:
您正在粘贴一个带有斜线的值作为搜索表达式的一部分。它最终是:(
其中 PWD 代表任何文字目录规范。)由于您无法转义斜杠,因此除非您使用替代分隔符,否则这总是一个问题。
You might want to try:
You're pasting a value with a slash in it as part of the search expression. It ends up as:
(Where PWD stands for any literal directory spec.) Since you can't escape the slash, that's always going to be a problem unless you use an alternative delimiter.
由于您的变量包含“/”,您需要对正则表达式使用不同的字符,您也可能需要使用 quotemeta 或 \Q..\E 正则表达式中的变量可以包含特殊字符
请参阅这篇文章了解更多详细信息 how-do-i-handle-special-characters-in- a-perl-正则表达式
Since your variable contains '/' you need to use a different character for regular expressions, also you may want to use quotemeta or \Q..\E in regular expressions having variables which can contain special characters
Refer to this post for more details how-do-i-handle-special-characters-in-a-perl-regex