[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: #! syntax



Quoting D-Man (dsh8290@rit.edu):
> On Mon, Feb 26, 2001 at 05:50:54PM +0100, Carel Fellinger wrote:

> | You could consider:
> | 
> |    #!/usr/bin/env perl
> | 
> | as more installs will have env in the same place.
> | 
> 
> This is the correct way to begin python scripts (I can't say how the
> perl community feels) :
> 
> 
> #!/usr/bin/env python
> 
> # python code here

Well it's difficult to see much difference between these two
suggestions.

> The idea is that env knows where stuff on the current machine is, so
> simply ask it for the interperter you want (python, perl, bash, etc).

AFAIK env knows nothing about "where stuff is". It just modifies
the environment (nothing to do here as it happens) and runs perl
or python (which are found through $PATH).

> On a tangent, is there a way to manually configure env as to program
> locations?  In particular, how can I have env on my cygwin
> installation know where python is (Win32 python build)?  For now I
> have my python script in foo.py with a wrapper foo that does :
> 
> #!/bin/bash
> 
> python foo.py $*

I'm not sure what your difficulty is. Your $PATH presumably contains
python so the env trick should work. The env trick is only necessary
because #! requires the full path: although the path to perl may vary
on different systems, the path to env is usually the same, /usr/bin/env.
So you can use one script on the different systems and $PATH (different
on different systems) will actually find perl, python or whatever.

If you want to run a specific version of python, then just write its
path in your script:

#!/usr/bin/env /weird/path/python32

# python code here

Cheers,

-- 
Email:  d.wright@open.ac.uk   Tel: +44 1908 653 739  Fax: +44 1908 655 151
Snail:  David Wright, Earth Science Dept., Milton Keynes, England, MK7 6AA
Disclaimer:   These addresses are only for reaching me, and do not signify
official stationery. Views expressed here are either my own or plagiarised.



Reply to: