$?从 Makefile 运行时被忽略,但作为 bash 命令复制粘贴时工作正常
我试图从 Makefile 自动运行命令:
make lint:
pylint --rcfile=.pylintrc --disable=R,C,W1203,W0702,W0621 main.py || pylint-exit $?
然后运行命令:
make lint
我收到以下错误 -
用法:pylint-exit [-h] [-efail] [-wfail] [-rfail] [-cfail] PYLINTRC make: *** [Makefile:6: lint] 错误 1
可能是因为 shell 期望命令末尾有一个整数,但实际上没有 因为它无法识别 $?
如果我直接作为 bash 命令运行相同的命令:
pylint --rcfile=.pylintrc --disable=R,C,W1203,W0702,W0621 main.py || pylint-exit $?
一切都会按预期运行:
main.py:5:0: W0611: 未使用的 numpy 作为 np 导入(未使用的导入)
------------------------------------------------------------ ------------------- 您的代码评分为 9.76/10(上次运行:9.76/10,+0.00)
提出了以下消息:
- 发出警告消息
未检测到致命消息。优雅地退出...
这种行为有解决方法吗?我想这与 Makefile 中处理通配符的方式有关。
谢谢!
I am trying to automatically run a command from a Makefile:
make lint:
pylint --rcfile=.pylintrc --disable=R,C,W1203,W0702,W0621 main.py || pylint-exit $?
and then run the command with:
make lint
I get the following error -
usage: pylint-exit [-h] [-efail] [-wfail] [-rfail] [-cfail] PYLINTRC
make: *** [Makefile:6: lint] Error 1
probably because the shell expects an integer at the end of the command, but there is none
because it doesn't recognize the $? sign.
if I run the same command directly as a bash command:
pylint --rcfile=.pylintrc --disable=R,C,W1203,W0702,W0621 main.py || pylint-exit $?
everything runs as expected:
main.py:5:0: W0611: Unused numpy imported as np (unused-import)
------------------------------------------------------------------ Your code has been rated at 9.76/10 (previous run: 9.76/10, +0.00)
The following messages were raised:
- warning message issued
No fatal messages detected. Exiting gracefully...
Is there a workaround for this kind of behavior - I guess it is something with the way wildcard signs are handled in Makefiles.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$
既是 make 元字符,也是 shell 元字符。您需要转义它,因此 make 会忽略它并将其传递给 shell。$
is both a make and shell metacharacter. You'll need to escape it so make ignores it and passes it to the shell.$?
是make
参数扩展。您希望通过将$
加倍,将$?
按字面意思传递到执行pylint-exit
的 shell。$?
is amake
parameter expansion. You want the$?
to be passed literally to the shell that executespylint-exit
, by doubling the$
.