I am trying to understand the impact of exclamation (and read) in following commands in a Makefile in a codebases I work with.
check-format:
! gofmt -s -l . | read;
! go run golang.org/x/tools/cmd/goimports -l . | read;
These commands are run on Mac and other unix based systems.
A lot of the questions about exclamation mark in bash scripts mention they are for history expansion. But, in context of the above Makefile, it does not seem to make sense.
Would appreciate any help in understanding what the ! and the piped read accomplish here. Thank you!
!in Linux tools breaks out to a shell. For example, inviI can type:4,7 ! tr 'a-z' 'A-Z', which will pass lines 4 - 7 totron stdin, and replace them in the edit with the stdout, thereby uppercasing those lines. As the text to the right of each of your!seems to be a shell command, I assume the line in your makefile is replaced by the output of the command, and then re-processed as makefile syntax.!may be deprecated or non-Linux. GNU/make has a Shell Function command and a!=operator that also return the output of an external command into the makefile itself. <www.gnu.org/software/make/manual/make.html#Shell-Function>!and|have their normal shell pipeline meanings in this context . In particular,man gofmtsays that-stries to simplify the code, while-lseems to print the filename to stdout if the result is different; sincereadexits successfully if it reads something,!inverts that meaning so the rule succeeds if no file fails thegofmt -stest. I haven't looked at the second command but I suspect something similar.