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

Andrew Barnert abarnert at yahoo.com
Thu Mar 12 02:39:11 CET 2015


On Mar 11, 2015, at 4:42 PM, random832 at fastmail.us wrote:
> 
>> On Wed, Mar 11, 2015, at 15:43, Neil Schemenauer wrote:
>> Traditionally the OS only passes the first option to the
>> interpreter so anything after that could be used to pass 3.x
>> specific options.
> 
> I think some OSes pass everything after the interpreter as one long
> string rather than ignoring extra arguments.

And some pass all the arguments separately. Try "#! /usr/bin/env python -O -i" on different platforms; you'll find all three behaviors.

> Is there any standard for
> this?

Nope. POSIX allows for compliant sh implementations to do shbang processing by saying that 'If the first line of a file of shell commands starts with the characters "#!", the results are unspecified". That means there's actually no way to write portable #! scripts according to POSIX. Given that POSIX doesn't require any particular path to env, that's not too surprising; you're already non-portable using /usr/bin/env

At least (as of 2008) POSIX does ban doing shbang processing inside the exec functions instead of in sh. (Although even there, Linux's pluggable executable formats provide a way around that...) Somewhere in the POSIX standard, there's a non-normative recommendation that if you want an application to depend on #!, you should include an installer that uses getconf PATH, searches for a suitable interpreter, and used sed to change the shbang to point at the absolute path to that interpreter.

So, forget theory; in practice, what's portable? Using exactly one argument works as expected on any system you're likely to find. Which means if you want to use /usr/bin/env instead of using an installer, you don't get any arguments.



More information about the Python-ideas mailing list