[Python-ideas] Migration of /usr/bin/python to python3

Andrew Barnert abarnert at yahoo.com
Thu Mar 12 11:29:59 CET 2015


On Mar 12, 2015, at 1:25 AM, Oleg Broytman <phd at phdru.name> wrote:
> 
> Hi!
> 
>> On Wed, Mar 11, 2015 at 07:58:55PM -0500, Skip Montanaro <skip.montanaro at gmail.com> wrote:
>>> On Mar 11, 2015 3:50 PM, "Ryan Gonzalez" <rymg19 at gmail.com> wrote:
>>> 
>>> No; this won't work:
>>> 
>>> #!/usr/bin/env python -x -3
>>> 
>>> As Oleg said, anything in the hashbang can only be passed one argument.
>> It's not the kernel that invokes that; it's the shell.
> 
>   Why do you think it's the shell? It's exec() system call.

Maybe he thinks that because he read the POSIX standards, which forbid doing it in exec, or the man pages for his system's execl or sh?

The earliest versions of Unix shbang processing were done in exec, but that turned out to lead to a variety of problems, so most stopped, and after a few decades, POSIX finally (in 2008) forbade it: exec must use the standard shell processor for anything that's not a recognized, loadable executable format. The standard shell processor (usually /bin/sh) is then allowed to do anything it wants for files starting with "#!" (the behavior is left undefined by the standard); on pretty much all systems what it does is (one of the three variations of) the usual shbang process.

(As I briefly mentioned earlier, there is a way to weasel around the wording, and Linux does give you a way to use it: the linux kernel has pluggable executable formats, and there's nothing stopping you from, say, defining an executable format that's recognized by treating "#!/usr/bin/env python" as a magic number and "loaded" by exec'ing the Python interpreter, which would still be within the letter of the standard.)

> 
>> Skip
> 
> Oleg.
> -- 
>     Oleg Broytman            http://phdru.name/            phd at phdru.name
>           Programmers don't die, they just GOSUB without RETURN.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list