为什么 sed 的正则表达式会在 Makefile 中中断?

发布于 2024-08-28 06:16:57 字数 580 浏览 3 评论 0原文

我使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-09-04 06:16:57

\+ 没有任何特殊含义。另外,我认为 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 的调用会产生不同的结果(也许,它有改变了?)

  • (这就是问题,请参阅下面的评论)< /strong> Make 使用的 shell(默认为 /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 file jslint 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 inserting echo statement in your commands, just to tell Make got to executing them:

    jslint :
        echo I got here
        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/'
    
  • your call to java yields different results (perhaps, it has changed?)

  • (this is the problem, see comments below ) the shell used by Make (it is /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,\}.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文