logoalt Hacker News

forgotpwd16last Tuesday at 3:39 PM2 repliesview on HN

Go has explicitly rejected adding shebang support, mandating this hack, due to being considered "abuse of resources"[0]. Rather `gorun`, which is also called a mistake by Pike, is recommended instead. And can alter this method so not to need to hardcode a path.

    /// 2>/dev/null ; gorun "$0" "$@" ; exit $?
>Good-old posix magic. If you ask an LLM, it'll say it's due to Shebangs.

Well, ChatGPT gives same explanation as article, unsurprising considering this mechanic has been repeated many times.

>none other fits as well as Go

Nim, Zig, D, all have `-run` argument and can be used in similar way. Swift, OCaml, Haskell can directly execute a file, no need to provide an argument.

[0]: https://groups.google.com/d/msg/golang-nuts/iGHWoUQFHjg/_dbL...


Replies

clktmrlast Tuesday at 6:00 PM

There is also yaegi, a Go interpreter, which might be a better choice for small scripts than 'go run'.

https://github.com/traefik/yaegi

show 1 reply