bash - 在 Go makefile 中使用 bash 命令

标签 bash macos go makefile

通过命令行 (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/

相关文章:

bash - 如何清除/删除终端中的当前行?

bash - 在 Bash 中自定义 "command not found"消息

linux - 将HDFS Hadoop中的最后5个更新文件复制到bash中的目标文件夹

string - Bash 正则表达式仅用于数字和点

macos - WebStatus 不会编译 : The "jquery@3.4.1" library could not be resolved by the "cdnjs" provider

unit-testing - 作为接口(interface)访问的单例的单元测试

ruby-on-rails - 如何在 mac vim 的新选项卡中加载插件?

safari - 如何让 XCode/GDB 融入 Safari 5.1 NPAPI 插件?

go - 我应该在生产中使用 go 模块吗

postgresql - sqlx 将 postgres 数组扫描到结构中