我遇到了一些奇怪的拒绝许可错误,我不知道可能是从哪里来的.

$ go run .
Hello from go
$ make run
go run .
make: go: Permission denied
make: *** [Makefile:2: run] Error 127
$ make run2
echo "Make says hello" ; go run .
Make says hello
Hello from go
$ cat Makefile 
run:
    go run .

run2:
    echo "Make says hello" ; go run .
$ cat main.go 
package main

import "fmt"

func main() {
    fmt.Println("Hello from go")
}

我的终端是运行在Ubuntu 22.04上的bash.

我的run目标和直接运行GO之间有什么不同,可能会导致权限被拒绝错误?

runrun2之间有什么区别,允许它在一个中工作,而不是在另一个中工作?

编辑:使用-d/--trace运行Make

$ make -d run
<...snip...>
 No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'run'.
 File 'run' does not exist.
 Finished prerequisites of target file 'run'.
Must remake target 'run'.
go run .
make: go: Permission denied
make: *** [Makefile:2: run] Error 127
$ make --trace run
Makefile:2: target 'run' does not exist
go run .
make: go: Permission denied
make: *** [Makefile:2: run] Error 127
$ make --trace run2
Makefile:5: target 'run2' does not exist
echo "Make says hello"; go run .
Make says hello
Hello from go

推荐答案

这是由于GNU make中的一个错误(实际上是gnulib中的一个错误).这意味着您在PATH上的某个目录中(在包含go可执行文件的实际目录之前)有一个名为godirectory.

所以,如果你有一个directory /usr/bin/go/.,你的PATH上有/usr/bin,你会看到这个问题.

您应该判断您的PATH,并确保删除包含这些子目录的所有目录.如果不能从PATH中删除该目录(在PATH上需要包含子目录的目录是不常见的,但我想这是可能的),并且不能将go目录重命名为其他名称,则必须通过添加特殊字符来确保GNU make调用一个shell .只要;就足够了:

run:
         go run . ;

Go相关问答推荐

Golang Cososdb-gremlin连接

Term~T中的类型不能是类型参数,但可以是引用类型参数的切片

Go协议缓冲区导入问题

map 中的多个函数类型,Golang

使用!NOT运算符的Golang文本/模板多个条件

Go:为什么我不能比较 net.Addr

go-chi: 接受带有反斜杠的 url 路径参数

如何找到一个空闲的TPM句柄来保存新的密钥对对象?

Golang text/template中的startswith函数 - 入门教程

如何使用名称具有包名称的嵌套 struct 启动 go struct

如何在 Go 中编写示例测试?

如何仅提取时间作为持续时间

使用 golang 生成 vim

如何在 Docker 容器中使用私有存储库进行身份验证

如何在 helm 中将字符串连接到 .AsConfig 的结果?

如何使用struct的方法清除除某些字段之外的struct值

即使一个测试用例失败,如何运行所有测试用例

Ginkgo/Gomega panic 测试失败

HTTP 重定向不呈现新页面

Go:如何通过 GIN-Router 从 AWS S3 将文件作为二进制流发送到浏览器?