Strange syntax error, occurs only when script is executed directly

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Apr 22 08:36:42 EDT 2014


On Tue, 22 Apr 2014 12:29:56 +0200, Antoon Pardon wrote:

> I am workin on a solaris 11 machine. The python version is 2.7.6 path to
> python is /opt/local/bin/python.

Are you sure about that? You ought to double check that /opt/local/bin/
python is what you think it is, and not (say) a symlink to a different 
binary.


> 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.



[...]
> However if I call the script directly and want the #! line do its work I
> get the following error.
> 
> # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head
> /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `('
> /usr/local/bin/ldapwatch: line 3: `class vslice(object):'

That's not a Python syntax error, so its something else failing before 
Python gets to see it. The only way I can reproduce this is to execute 
Python code using sh:

[steve at ando ~]$ cat ./test2
class X(object):
    pass

print X
[steve at ando ~]$ ./test2
./test2: line 1: syntax error near unexpected token `('
./test2: line 1: `class X(object):'


> Does anyone have an idea where I should look to fix this?

Ask your local Solaris expert :-)

This appears to be the same symptoms:

http://www.linuxmisc.com/12-unix-shell/581d028236386dae.htm



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list