Name is misleading, but still. The goal of this is to be able to compile and run a C file in one line, with the C source file containing all instructions needed to compile itself when interpreted as a shell script.
So these cases need to be supported:
curl URL | bash
wget URL; source SCRIPT ARGS...
wget URL; chmod +x SCRIPT; ./SCRIPT ARGS...
For development purposes, this also needs to be a valid C file, so this must work too:
gcc source.c -o program
Always creates a binary file with specified name. Can overwrite itself when executed as file.
Relies on quoted heredocs and uses gcc which compiles code from stdin. Of course, the code may not contain the delimiter.
Tested on bash and ash shells and gcc 7.2.1. I'm not sure if traliling # characters are allowed or it's just gcc. We need them though.
Previous version couldn't overwrite itself when executed as a target file, because after new contents were written, bash couldn't read further instructions. Now we use a
.tmpfile and overwrite ourselves whengccis executed, but since&&is used, bash should buffer these instructions. That means now it won't overwrite itself when executed as target file with.tmpsuffix, but that's acceptable for now.