in reply to #! -- why doth thou exist?

#! is the "magic number" for interpreted languages. The kernel looks at your file that you're trying to run, and determines what "mode" to run it in. (Some OS's only support a single binary type, but many support multiple - e.g., ELF and libc formats on Linux, or Win32, Win16, and OS/2-16 on Windows, etc.) One of these modes, on unix systems anyway, is the "interpreted" mode where the kernel reads that first line, and calls that executable on the file instead.

So, when you run "./test.pl", the kernel looks at your file and sees the #! magic number, and then reads the line, sees to run "/Users/punkish/bin/perl ./test.pl", and does so. In turn, it looks at /Users/punkish/bin/perl, sees that its magic number is a binary native to MacOSX, knows how to run it, and does so.

However, the kernel does not know what ~ is - that's something your shell knows how to interpret. If you're on the commandline, the shell replaces that character before passing it to the kernel, while if it's in the #! line, the kernel doesn't know how to deal with it, and aborts running the file.

Welcome to unix :-)

Replies are listed 'Best First'.
Re^2: #! -- why doth thou exist?
by punkish (Priest) on Aug 25, 2005 at 14:39 UTC
    Tanktalus++

    My commendations for a most excellently lucid explanation.

    My thanks to everyone else as well.

    --

    when small people start casting long shadows, it is time to go to bed