[Fwd: directly executing a python script in Unix]

Antaeus Feldspar feldspar at ix.netcom.com
Mon Feb 4 18:16:08 EST 2002


Johannes accidentally replied to me rather than to the newsgroup, so:

Johannes Nix wrote:
> 
> Antaeus Feldspar <feldspar at ix.netcom.com> writes:
> 
> > > "./myscript.py".  However, when I try this, I get an error "Command
> > > not found.".  I get the same error under both Linux and Solaris.
> 
> > Hmmmm.  I tried a few things, none of which reproduced your error:
> >
> > * trying to run the script without execute permission
> > * running without any "if __name__ == '__main__':" code
> > * subtracting/adding spaces between the "#!" token and the path
> 
> I've read once that Linux doesnt finds she-bang command scripts if
> they end with something different from a newline - for example a
> carriage return plut a newline (MS Windows / DOS convention). So it's
> possible to write such a script under DOS, which is visually identical
> but won't run under Linux.
> 
> jnix at zosma:/mnt/newhome/jnix > od -t a s.py
> 0000000   #   !   /   u   s   r   /   b   i   n   /   p   y   t   h   o
> 0000020   n  cr  nl   p   r   i   n   t  sp   1  nl
> 0000033
> jnix at zosma:/mnt/newhome/jnix > chmod u+x s.py
> jnix at zosma:/mnt/newhome/jnix > ./s.py
> bash: ./s.py: No such file or directory
> jnix at zosma:/mnt/newhome/jnix >
> 
> Johannes



More information about the Python-list mailing list