Grep退出代码中Makefile中的条件逻辑

时间:2016-09-24 17:57:52

标签: makefile exit-code

我正在Makefile中编写一个connivence函数,我在捕获grep状态代码返回的决策时遇到了一些麻烦。

我知道command that exits with a non-zero status will terminate Make。而且我也知道make默认会产生一个sh shell,所以我不确定这是否会让事情变得复杂。

我正在运行此命令:golint | grep -v "comment on exported"如果命令成功完成(1没有输出;所有输出都已过滤)并且grep,则返回0如果还有未经过滤的输出。不确定为什么grep这种方式是违反直觉的,但这不是重点。

我希望成功echo 'No liniting issues',并在失败时打印未经过滤的行。

我认为这些排列中的任何一种都可行:

lint:
        # Will never print 'No linting issues'
        ! golint | grep -v "comment on exported" || echo 'No linting issues'
        ! `golint | grep -v "comment on exported"` || echo 'No linting issues'
        ! (golint | grep -v "comment on exported") || echo 'No linting issues'

        # Exits with syntax error: unexpected end of file
        if [ $(golint | grep -v "comment on exported") -ne 0 ]; then
          echo 'No linting issues'
        fi

这似乎是一件非常简单的事情,所以这个问题更让人感到沮丧,因为它让它变得更有效。

我很感激帮助!

0 个答案:

没有答案
相关问题