#!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
Written by Tarcísio Gruppi
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#