为什么 sed 的正则表达式会在 Makefile 中中断?
我使用的是 GNU Make 3.81,并且我的 Makefile 中有以下规则:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/'
如果我直接在命令行上输入它,则效果很好,但如果我使用“make jslint”运行它,则正则表达式不匹配。 Makefile 中将 \+
替换为 \{1,\}
,它就会起作用:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\{1,\}\) character \([0-9]\{1,\}\)/mango.js:\1:\2/'
但是,如果我在 Makefiles,或者这是一个错误?
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/'
This works fine if I enter it directly on the command line, but the regular expression does not match if I run it with "make jslint". However, it works if I replace \+
with \{1,\}
in the Makefile:
jslint :
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint at line \([0-9]\{1,\}\) character \([0-9]\{1,\}\)/mango.js:\1:\2/'
Is there some special meaning to \+
in Makefiles, or is this a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
\+
没有任何特殊含义。另外,我认为 GNU Make 没有任何问题。即使在第一种情况下,表达式也可能确实匹配,但问题可能是
make jslnit
code>jslint 已存在于当前目录中。在这种情况下,它不会被视为应该调用正确命令的目标。可以肯定的是,尝试在命令中插入echo
语句,只是为了告诉 Make 执行它们:<前><代码>jslint:
回声我到了这里
java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
| sed 's/Lint 位于行 \([0-9]\+\) 字符 \([0-9]\+\)/mango.js:\1:\2/'
您对
java
的调用会产生不同的结果(也许,它有改变了?)/bin/sh
,可以按如下所示进行更改 此处)和您输入命令的 shell(检查两个版本是否匹配)不同,和它在某种程度上影响你正在做的事情。例如,在这些 shell 中调用不同默认版本的 sed,其中\+
不等于\{1,\}.
\+
doesn't have any special meaning. Also, there's nothing wrong with GNU Make, I suppose.The expressions probably does match even in the first case, but the thing is probably that either
you call
make jslnit
when a filejslint
already exists in the current directory. In this case it won't be considered as a target, for which the proper commands should be invoked. To be sure, try insertingecho
statement in your commands, just to tell Make got to executing them:your call to
java
yields different results (perhaps, it has changed?)/bin/sh
by default, and can be changed as shown here) and the shell you enter commands to (to check if both versions match) differ, and it in some way affects what you're doing. For example, different default versions of sed are called in these shells, and in one of them\+
is not equivalent to\{1,\}
.