从shell脚本运行Golang脚本

时间:2017-03-17 19:13:25

标签: bash go automator

每当我登录OSX时,我都会尝试运行golang程序。我正在尝试使用Automator的以下脚本:

#!/bin/sh
export GOPATH=/Volumes/DTSE9/worker
go run /Volumes/worker/worker.go

每当我使用Automator运行它时,它会告诉我go: command not found

1 个答案:

答案 0 :(得分:1)

创建一个像file.go这样的文件,其内容应如下所示:

///path-to/bin/go run $0 $@; exit $?

package main

func main() {
    println("Hello World!")
}

然后运行chmod +x file.go,然后您可以将其./file.go p1 p2执行。

编辑:这适用于Ubuntu。我没有看到OSX有问题。

相关问题