
FAST "shebang" for C - Jeff-Russ
This is my first post here so hopefully I&#x27;m doing this right. I found this thread https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9144467 from a while back and it got me experimenting with similar things. I found this solution which seems to be MUCH faster:<p><pre><code>  &#x2F;&#x2F;usr&#x2F;bin&#x2F;env gcc `basename &quot;$0&quot;` -o _;.&#x2F;_ &quot;$@&quot;;rm _;exit
</code></pre>
When you make a C source file, say hello.c with this as the top line, and just run it directly, this line will call gcc on it&#x27;s own file name, and compile to a file just called _ (underscore). Then it will execute it, forwarding all arguments to it, then remove it, then exit (so it doesn&#x27;t try interpreting C code as bash or whatever). The whole thing is blazing fast, much faster than some popular solutions I found on GitHub even.
======
Jeff-Russ
It's safer to do $BASH_SOURCE instead of $0 but I really can't think of a
real-live scenario where it would matter here. Perhaps if you are chaining
calls but I'm not even sure that would work without trying it.

------
knz42
You should use use '&&' instead of ';' so that you don't end up running
another program should the compilation fail.

Also highly recommended to use '_$$' instead of plain '_'.

------
Jeff-Russ
also note that this is not entirely portable since some systems can send args
to /usr/bin/env gcc

