[katello-devel] Why #!/usr/bin/env ?

Eric Sammons esammons at redhat.com
Mon Jul 23 21:05:49 UTC 2012


----- Original Message -----
> On 07/23/2012 04:06 PM, Ewoud Kohl van Wijngaarden wrote:
> > On Mon, Jul 23, 2012 at 03:37:43PM -0400, Jordan OMara wrote:
> >> On 23/07/12 21:35 +0200, Miroslav Suchy wrote:
> >>> Why do you guys prefer #!/usr/bin/env ?
> >>>
> >>> I seen it twice in today pull requests and git grep show me it is
> >>> used several times in our code.
> >>>
> >>> I understand it may put in game e.g /usr/local/bin/ with locally
> >>> compiled python/ruby. But is it what we want? Do we guarantee,
> >>> that our code will work with locally modified version of
> >>> python/ruby?
> >>>
> >>> I always used plain #!/usr/bin/python or #!/usr/bin/ruby as it
> >>> gives me more control and less bug reports.
> >>>
> >>> Mirek
> >>>
> >> I actually had a stranger from the internet make a pull request on
> >> one
> >> of my random github projects and correct a ruby script from
> >> #!/usr/bin/ruby ->  #!/usr/bin/env ruby ; the same way we have it
> >> in
> >> our scripts. I'm curious as well
> > Can't speak for ruby, but in the python world virtualenv[1] is
> > popular
> > among developers. Then python can live in ~/myenv/bin/python as
> > well as
> > many dependencies under ~/myenv/lib/python2.X/site-packages which
> > /usr/bin/python will never find, or worse, different versions. I
> > imagine
> > something similar may exist in the ruby world.
> 
> Shouldn't distutils do the right thing in this case?
> http://docs.python.org/distutils/setupscript.html#installing-scripts
> 
> Adrian

I may be mis-understanding here or perhaps I am not familiar with all the cool features of distutils, but I was under the impression that this was related to the setup and packaging (for distribution) of pypi packages.  Again, unless I am missing something, this is not necessarily related to the use of #!/usr/bin/python v. #!/usr/bin/env python.

Again, WRT /usr/bin/python v. /usr/bin/env python, as I mentioned for me this is habit.  However, there are a number of discussion threads on the topic; http://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script for example.  I will continue to use /usr/bin/env python as it is habit and I have been in environments where the default PATH is altered to ensure the use of the "in-house" preferred binaries, usually stored in /opt/$pkg/bin or /usr/local/bin.

Again wrt virtualenv, here is an example:

$ virtualenv testme
$ cd testme
$ source bin/activate
$ which python
~/testme/bin/python

Note, if you were using /usr/bin/python you would _not_ be testing the python binary in "testme".

--Eric

> 
> _______________________________________________
> katello-devel mailing list
> katello-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/katello-devel
> 




More information about the katello-devel mailing list