What’s the appropriate Go shebang line?

//usr/bin/go run $0 $@ ; exit

example:

//usr/bin/go run $0 $@ ; exit
package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

go treat // as a single line comment
and shell ignore extra /

Update: Go installation may be in a different location. The syntax below will take that into account, and works for Macs:

//$GOROOT/bin/go run $0 $@ ; exit

Leave a Comment