0
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

get confused with this commend go tool vet . |& grep -v vendor;true and get error when make this...

$ 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
yiming wei
  • 11
  • 3
  • Your shell doesn't support `|&`. Either don't use the `|&` syntax, or use a shell that supports it. – JimB Feb 08 '19 at 02:35
  • my bash is version 4.4.19(1)-release (x86_64-pc-linux-gnu), or any recommendation on how to rephase above syntax around `|&`? – yiming wei Feb 08 '19 at 02:46
  • You're probably not using bash, the error says `/bin/sh`, which is often a more basic shell. Are you just asking what `|&` means? See https://stackoverflow.com/questions/35384999/what-does-mean-in-bash – JimB Feb 08 '19 at 02:55
  • so the whole sentence means ? `go tool vet . |& grep -v vendor;true` – yiming wei Feb 08 '19 at 03:08
  • Just a tip: you can tell vim to write swap files to a specific location. Add this to your .vimrc: `silent execute '!mkdir -p ~/.vim/mydir'`, then add the following lines `set directory=~/.vim/mydir`, `set backupdir=~/.vim/mydir`, and `set backupskip=~/.vim/mydir/*` – Elias Van Ootegem Feb 08 '19 at 17:36

1 Answers1

1

The command attempts to redirect both standard output and standard error to grep. The portable (and subjectively better) way to do that is

go tool vet . 2>&1 | grep -v vendor || true

The trailing true will cause the make command to succeed even if grep fails to find any matches (i.e. there are no output lines which do not contain vendor). Recall that make by default interrupts the compilation on the first error; this avoids an error for a command which is apparently only run for monitoring or possibly entertainment.

tripleee
  • 175,061
  • 34
  • 275
  • 318