Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
#! 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 :-) In reply to Re: #! -- why doth thou exist?
by Tanktalus
|
|