[Python-Dev] #! magic (original) (raw)

Jeroen Ruigrok van der Werven asmodai at in-nomine.org
Mon Jan 21 09:11:39 CET 2008


-On [20080120 18:38], Oleg Broytmann (phd at phd.pp.ru) wrote:

A shell has nothing to do with it as it is the OS (exec system call) that upon reading the magic of the file sees #! and executes the program (up to the first space) and pass to the program the first (and the only) parameter.

Yes, you are right. sigh It's been too long since I dug around the kernel on a daily basis.

I had totally forgotten about imgact_shell.c's parsing of the hashbang. As execve(2) documents on FreeBSD:

An interpreter file begins with a line of the form:

    #! interpreter [arg]

When an interpreter file is execve'd, the system actually execve's the specified interpreter. If the optional arg is specified, it becomes the first argument to the interpreter, and the name of the originally execve'd file becomes the second argument; otherwise, the name of the originally execve'd file becomes the first argument. The original argu- ments are shifted over to become the subsequent arguments. The zeroth argument is set to the specified interpreter.

-- Jeroen Ruigrok van der Werven <asmodai(-at-)in-nomine.org> / asmodai イェルーン ラウフロック ヴァン デル ウェルヴェン http://www.in-nomine.org/ | http://www.rangaku.org/ The greatness of a nation and its moral progress can be judged by the way its animals are treated.



More information about the Python-Dev mailing list