bash - 去工具 vert 。 |& grep -v vendor ;真

标签 bash go makefile

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/

相关文章:

c - 如何使一个 makefile 引用另一个 makefile

bash - 将段错误消息从 C++ 程序重定向到文件

linux - 使用命令行和完整路径启动 Bash 脚本

Linux parents 文件的父路径

json - 将 JWT 负载转换回结构

vim - 设置环境 - $GOPATH

c - 有没有办法查明提供的密码是否与特定用户的实际密码匹配?

c - PETSc 未定义引用

makefile - 显式地创建一个具有变量名的目标

regex - 在参数 bash 中查找并替换字符串