3 ms·
That's quite cool, but minor point of pedantry: that's not a shebang. A shebang is interpreted by the operating system, which uses it to find and launch an inte
by zbentley 9y ago
That's quite cool, but minor point of pedantry: that's not a shebang. A shebang is interpreted by the operating system, which uses it to find and launch an interpreter for a file.
Compared to that, the example snipped you provided is doing many more, and different things:
1. Launches a shell language interpreter: usually the system default POSIX-compliant sh, but could (rarely) be something else. Compared to "read the first line, and if it's a shebang launch python or whatever" in the kernel, this is massively complicated: it starts another whole runtime. Run "strace" on a file that just does "///bin/true; sleep 1000" to see exactly how much is happening just for that shell launch.
1. Executes /bin/true. It's probably present everywhere, and probably the right program, but still an assumption.
2. Evaluates a bunch of string slinging statements in the shell to interpolate arguments, then replaces itself via "exec".
3. Launches /usr/bin/env (hopefully the right program, and hopefully in the right place) to find the go interpreter.
4. env (hopefully) also calls "exec" again and then launches the go run command to start the compilation/execution sequence.
That's a lot of stuff. Pretty garden-variety stuff, but still a lot of additional complexity. A shebang adds none of it, though "trampolining" shebangs (which themselves are just programs to do basically this) can reintroduce some internally.
That's the beauty of the shebang as a trick for truly interpreted languages: it's extremely direct and simple as a means of getting your code executing on your desired runtime.