Last Updated: February 25, 2016
· txgruppi
10464074 938292239583056 7575720943166745998 n

#!go run - run go as a script language

The magic

Add //usr/bin/env go run "$0" "$@"; exit to your go code and run it like shellscript, python, ruby...

Step by step

  • Create a file called hello-world.go with this code:
//usr/bin/env go run "$0" "$@"; exit

package main

import "log"

func main() {
  log.Println("Hello World")
  • Run chmod u+x hello-world.go
  • Run ./hello-world.go and watch the magic
Say Thanks

1 Response
Add your response


That is a great tip Tarcísio. Excellent for who is learning, like me, and has no idea why the src folder structure is required. Thank you.

over 1 year ago ·
Filed Under