通过命令行 (MacOS) 使用 go run
时,可以排除 _test.go
文件。
go run $(ls -1 dir/*.go | grep -v _test.go)
但是,似乎该命令并未通过 Go 生成文件以类似方式使用。例如,
start:
go run $(ls -1 dir/*.go | grep -v _test.go)
和
start:
go run `$(ls -1 dir/\*.go | grep -v _test.go)`
两者都会导致,
go run: no go files listed
在 Go 生成文件中使用 grep
和类似命令的正确方法是什么?
最佳答案
美元符号对于 make 来说很特别:它们引入了 make 变量和函数。如果你想在你的食谱中使用文字美元符号,你需要通过加倍来转义它:
start:
go run $$(ls -1 dir/*.go | grep -v _test.go)
关于bash - 在 Go makefile 中使用 bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51758105/