Run Golang script from shell script

血红的双手。 提交于 2019-12-11 07:29:44

问题


I'm trying to run my golang program whenever I log into OSX. I'm trying the following script with Automator:

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

Whenever I run this with Automator, it tells me go: command not found


回答1:


Create a file like say file.go and it's content should look like:

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

package main

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

Then run chmod +x file.go and then you can execute it as ./file.go p1 p2.

Edit: This works on Ubuntu. I did not saw that OSX was in question.



来源:https://stackoverflow.com/questions/42865472/run-golang-script-from-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!