logoalt Hacker News

xg15last Tuesday at 1:13 PM2 repliesview on HN

So the entire reason why this is not a "real" shebang and instead takes the roundtrip through the shell is because the Go runtime would trip over the # character?

I think this points to some shortcomings of the shebang mechanism itself: That it expects the shebang line to be present and adhering a specific structure - but then passes the entire file with the line to the interpreter where the interpreter has to process (and hopefully ignore) the line again.

I know that situations where one piece of text is parsed by multiple different systems are intellectually interesting and give lots of opportunities for cleverness - but I think the straightforward solution would be to avoid such situations.

So maybe the linux devs should consider adding a new form for the shebang where the first line is just stripped before passing the file contents to the interpreter.


Replies

wyufrolast Tuesday at 1:51 PM

It doesn't pass the file contents at all, it passes the file path.

show 1 reply
eichinlast Tuesday at 5:40 PM

Linux already did one better: binfmt_misc (see https://blog.cloudflare.com/using-go-as-a-scripting-language... for using it for a much cleaner way of using it to use gorun on executable *.go files.)