News for hackers. Stuff that matters.
Re:Shebang Quine by 0x0 on Friday May 20, 2016 @10:40AM (#11738136)
I don't think bash is involved here?
Re:Shebang Quine by Tyr42 on Friday May 20, 2016 @10:55AM (#11738295)
I don't think so either. It's something in the implementation of `execv` I think.

    #include <unistd.h>                                                             
                                                                                
    int main() {                                                                    
        execl("cat-quine", "cat-quine", NULL);                                      
        return 0;                                                                   
    }
Is sufficient to have this work.
Re:Shebang Quine by khc on Friday May 20, 2016 @11:36AM (#11738674)
An entire generation of programmer has grown up not knowing that this is implemented in the kernel.
Re:Shebang Quine by cyphar on Friday May 20, 2016 @12:19PM (#11739085)
I remember being surprised by this and then realising, "wait, of course it's in the kernel -- that's so much nicer from a usability and sanity standpoint".
Re:Shebang Quine by cyphar on Friday May 20, 2016 @12:19PM (#11739092)
It's implemented in the kernel. Look at fs/binfmt_script.c in the Linux kernel source tree for an example.
Re:Shebang Quine by geon on Friday May 20, 2016 @12:57PM (#11739436)
Re:Shebang Quine by kovek on Friday May 20, 2016 @10:52AM (#11738248)
More precisely:

  - The shell finds opens up the file you want to execute

  - It gets the first line of the file

  - It figures out what program to execute

  - It calls fork()

  - In the new process, it executes the program (using exec()) and passes the file as the input to the program.
Re:Shebang Quine by Tyr42 on Friday May 20, 2016 @10:56AM (#11738304)
The shell is not involved in looking at the first line of the program, that's what happens in `exec`.