On Mon, Dec 30, 2024 at 11:16:37AM +1100, raf <g...@raf.org> wrote: > Rather than expecting all C compilers to be modified to > ignore the #! line, it should be possible to configure > /bin/sh to do the desired thing. If a file is > executable and has no #! line, the kernel will execute > it via /bin/sh. Anyone who wants this facility could > create a .profile file (or similar) that checks for a > file argument, and checks if it is C source, and then > arranges for it to be compiled and executed and clean > up afterwards (or not). I don't think /bin/sh or any C > compilers would need to be modified. The actual dotfile > is left as an exercise for the reader. :-)
No, this won't work. My /bin/sh is dash which doesn't document when ~/.profile or /etc/profile are executed, but my default ~/.profile (seems to be part of bash) claims that it's only run for login shells. So /bin/sh would need to be changed to support a dotfile for non-login shells. But that would probably be easier than convincing the ISO to allow preprocessors to ignore #! lines to get all compilers to do it. Rather than changing dash (and all other versions of sh), it could be possible to write a small program that performs the check and actions described above, install it as /bin/sh, and if the check fails it can exec the real /bin/sh instead. But this would slightly slow down all uses of /bin/sh. cheers, raf