Stupid question: Making scripts python-scripts

Bill Mill bill.mill at gmail.com
Thu Jul 21 17:16:11 CEST 2005


On 7/21/05, Bill Mill <bill.mill at gmail.com> wrote:
> On 7/21/05, Jan Danielsson <jan.danielsson at gmail.com> wrote:
> > Hello all,
> >
> >    How do I make a python script actually a _python_ in unix:ish
> > environments?
> >
> > I know about adding:
> > #!/bin/sh
> >
> >    ..as the first row in a shell script, but when I installed python on
> > a NetBSD system, I didn't get a "python" executable; only a "python2.4"
> > executable.
> >
> >    Adding "#!/usr/pkg/bin/python2.4" as the first row in the script
> > would probably work, but that would be too specific for the system I'm
> > using, imho.
> >
> >    I saw someone using "#!/usr/bin/env python", but that failed on the
> > system I'm using, so I assume that's something specific too (or is the
> > installation broken?).
> 
> The env program [1], which usually exists at least on a linux system,
> executes the program given as its argument. Thus, "/usr/bin/env
> python" tries to executes python, which bash will then use to run the
> python script. As long as env exists, and python is somewhere in the
> PATH, this is a fairly portable way to run python scripts.
> 
> Does BSD really not come with the env program? I bet there's an
> equivalent you could symlink to it. Unfortunately, I've never BSDed,
> so I can't help you find it. To get a workable subset of the normal
> env functionality, you could try (assuming you use bash):
> 
> /home/llimllib $ echo "$@" > /usr/bin/env
> /home/llimllib $ chmod a+x /usr/bin/env
> 

ahhh, that should be:

/home/llimllib $ echo "\$@" > /usr/bin/env

otherwise bash tries to substitute into the string. Sorry bout that.

Peace
Bill Mill
bill.mill at gmail.com



More information about the Python-list mailing list