in reply to Re: Clarify My doubt on #!/usr/local/bin/perl
in thread Clarify My doubt on #!/usr/local/bin/perl

Still a bit off. The shebang line is actually interpreted by the kernel. When the kernel is told to run something, it checks the first few bytes of a file looking for a magic number to figure out how to execute something. The magic number for passing it to an interperter, such as the shell, is whatever the characters '#!' mean on that machine (depending on whether it's big-endian or little-endian).

For example, the magic number for ELF-formatted files is whatever ^?ELF is (where ^? is ctrl-?, not literally ^ and ?). The kernel uses this to use the ELF loader to load and execute that file. Other formats may be supported as well, depending on the kernel and architecture, and, on Linux, whether you've compiled in support for other formats.

  • Comment on Re^2: Clarify My doubt on #!/usr/local/bin/perl

Replies are listed 'Best First'.
Re^3: Clarify My doubt on #!/usr/local/bin/perl
by gellyfish (Monsignor) on Jun 09, 2005 at 10:07 UTC

    Er, yes. But it is through the agency of the execve(3) system call that this happens - you can see the code for this (for example) in /arch/i386/kernel/process.c in the Linux source. Okay in Linux it is further complicated by the binfmt_misc stuff, but in general for all Unix based OS execve is a kernel function that is exposed via the syscall mechanism in the C standard library.

    /J\