#!/bin/env problem Was: Re: Backwards emulation rather than backwards compatibility?

Oleg Broytmann phd at phd.pp.ru
Wed May 29 04:06:10 EDT 2002


On Tue, May 28, 2002 at 02:43:53PM -0700, Dave Kuhlman wrote:
> I typically start my scripts with a first line like the following:
> 
>     #! /usr/bin/env python
> 
> Quite a few files in Python2.2.1/Lib do likewise.
> 
> But, when I tried to add an option to be passed to the Python 
> interpreter by changing the first line to:
> 
>     #!/usr/bin/env python -t
> 
> I get an error message:
> 
>     /usr/bin/env: python -t: No such file or directory
> 
> Shouldn't I be able to pass a flag to the Python interpreter?  
> Looking at the env man page did not help.  And, quotes around 
> "python -t" did not help.  Is there another "trick"?

   There is no.

   Parsing the #! header is the job of the OS kernel, and all unicies do it
in the very simple way - they split the header into an interpreter
(/usr/bin/env, in this case) and its flags (python -t). Flags ARE NOT
SUPPOSED to have spaces, and are apssed to the interpreter as is.

   So the only way is to write

#! /usr/local/bin/python -O

   as I always do.

   If you want to distribute the script and worry about portability problem
- write setup.py and use "script" option. Distutils rocks!

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list