gpt4 book ai didi

php - 如何中止 makefile 中的 shell 命令错误?

转载 作者:行者123 更新时间:2023-12-02 12:00:18 24 4
gpt4 key购买 nike

我正在尝试编写一个 makefile 来打包一些 PHP 脚本。我还希望它在构建最终的 zip 文件之前检查语法错误(使用内置的 php lint 工具),以防止出现任何意外错误。

到目前为止我已经

all: dist
clean:
rm -f output.zip
dist: clean
for i in `find . -name "*.php"`; do php -l $$i; done
zip -r output.zip src -x "*/.*" "*/tests*"

这可行,但如果出现 PHP 错误,我希望它中断并且不继续构建 zip 文件(出于明显的原因)。目前,它们可能只是迷失在成功 lint 运行和 zip 文件的输出页面中。

我的处理方式正确吗?我应该使用 make 循环而不是 shell 循环吗?如何让 make 在 shell 命令错误时中止?

最佳答案

你可以这样做:

for i in `find . -name "*.php"`; do \
php -l $$i; \
if [ $$? -ne 0 ] ; then exit 42 ; fi \
done

关于php - 如何中止 makefile 中的 shell 命令错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6805253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com