all: gotool
@go build -v .
clean:
rm -f apiserver
find . -name "[._]*.s[a-w][a-z]" | xargs -i rm -f {}
gotool:
gofmt -w .
go tool vet . |& grep -v vendor;true
help:
@echo "make - compile the source code"
@echo "make clean - remove binary file and vim swp files"
@echo "make gotool - run go tool 'fmt' and 'vet'"
@echo "make ca - generate ca files"
.PHONY: clean gotool help
对这个推荐 go tool vet 感到困惑。 |& grep -v vendor ;真
做这个时会出错......
$ make
gofmt -w .
go tool vet . |& grep -v vendor;true
/bin/sh: 1: Syntax error: "&" unexpected
Makefile:7: recipe for target 'gotool' failed
make: *** [gotool] Error 2
最佳答案
该命令尝试将标准输出和标准错误重定向到 grep
。可移植的(主观上更好的)方法是
go tool vet . 2>&1 | grep -v vendor || true
尾随 true
将导致 make
命令成功,即使 grep
未能找到任何匹配项(即没有输出行不包含 vendor
)。回想一下,make
默认情况下会在出现第一个错误时中断编译;这避免了显然仅用于监视或娱乐的命令的错误。
关于bash - 去工具 vert 。 |& grep -v vendor ;真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54585229/