Strange syntax error, occurs only when script is executed directly

Andrew Cooper root at 127.0.0.1
Tue Apr 22 21:28:29 EDT 2014


On 22/04/2014 13:52, Chris Angelico wrote:
> On Tue, Apr 22, 2014 at 10:36 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>>> These are the 15 first lines of the script:
>>>
>>> #! /opt/local/bin/python
>>
>> This being Solaris, what happens if you remove the space between the hash-
>> bang and the path? On Linux it makes no difference, but Solaris tends to
>> be a bit more idiosyncratic about things like this.
> 
> I'm pretty sure the POSIX standard stipulates that a space there is
> optional. Should be no difference between "#!/" and "#! /" on any
> compliant OS. (But I can't right now find a citation for that, so I
> may be wrong.)
> 
> ChrisA
> 

man execve

4.3BSD implicitly mandates a space given its description of the shebang
line, while POSIX simply implies the presence of a space.

I have recently had to check this point.  All current kernel
implementations I cared to check would strip whitespace around the
interpreter, although Solaris was not one such implementation.

~Andrew



More information about the Python-list mailing list