我正在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
这似乎是一件非常简单的事情,所以这个问题更让人感到沮丧,因为它让它变得更有效。
我很感激帮助!