That first line starting with #!
is (on Linux) interpreted by the Linux kernel inside the implementation of execve(2) system call (which is invoked, after fork
, by your shell for most commands - those that are not functions and not shell builtins).
You could mention the absolute path of other executables (such as /usr/bin/env
, see env(1)). As a silly example, try making a script containing the only line #!/bin/cat /proc/self/maps
then make that script readable and executable (with chmod a+rx
) then run it.
The POSIX execve
specification does not mention any shebang specific processing, but all the Unix-like systems I worked on (Linux, SunOS, HPUX, AIX, ...) did process it specifically in execve
The bash
interpreter is skipping that line, as any other line starting with a #
, as a comment.
Look also at binfmt_misc (Linux specific).