Now what!?

Grant Edwards grante at visi.com
Sat May 10 18:57:20 EDT 2008


On 2008-05-10, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:

>> These are the minute details that bedevil the poor noob.  I've
>> read dozens of tutorials on different prog langs and have
>> never read a single thing on white space or blank lines
>> preceding a shebang.  Till now.  I always get
>
> 	Well... The "shebang" line is OS and shell specific

The "#!" is sort of a holdover from the "magic number" used
back in the day on Unix systems. Traditionally, the type of an
executable file on Unix systems was determined by a "magic
number" that was read from the first two bytes of a file:

  http://en.wikipedia.org/wiki/Magic_number_(programming)

Back then there was a text file somewhere that listed the
various 16-bit values and what they meant.  The "file" program
used that list to guess what a file was. It's gotten
considerably more complex since then, and the "magic" file has
syntax to specify fairly large/complex patterns that are used
to determine file types.  If you're curious, there's probably a
"magic" file somewhere on your system.  On Gentoo it's at
/usr/share/misc/file/magic, 
  
On a Linux system (and I presume on other Unixes), the kernel
itself (if built with the proper options) knows know how start
a "script" file that starts with the characters "#!".  When the
kernel is told to execute a file whose first two bytes are "#!"
(0x32,0x21), it knows to read the newline terminated path of an
executable starting at the byte following the "!" (the third
byte in the file).  The kernel then executes that file,
appending the name of the original "script" file to the argv
list.

-- 
Grant Edwards                   grante             Yow! My mind is making
                                  at               ashtrays in Dayton ...
                               visi.com            



More information about the Python-list mailing list