[Israel.pm] Best way to invoke a script in Unix

Mikhael Goikhman migo at homemail.com
Sun Oct 14 09:15:12 PDT 2007


On 14 Oct 2007 16:00:14 +0200, Yossi Itzkovich wrote:
> 
> I used to start all my scripts with:
> #! /full/path/to/perl
> 
> I saw others who used  env (perl) among other ways.
> 
> Is there a "best" way to do it?

Unless you are a user without root rights on a strange system without a
standard perl installation, the best way is to use "#!/usr/bin/perl".

In most of the cases (that is close to 100% on a sane modern POSIX
system) there is a good perl binary installed at this location. And in
rare cases when there is not or you need a different one, you may create
a symlink or a shell wrapper /usr/bin/perl to call the correct perl
executable depending on the current working directory or the user.

Other solutions although may be fine for some specific project, can't be
suggested in general, since they are either non-portable (call an
executable unexisting on other systems) or unsecure (may do different
things depending on the user PATH).

One more shortcoming of the "/usr/bin/env perl" method is that you can't
specify additional parameters to "perl", like "-w" or "-C0". At least on
all systems I can find. So Wikipedia lies here in one of its examples.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list