Magic Word


Table of Contents

Weird(?) magic word for sh to invoke perl under Linux 
magic word for shell 
No such file or directory 
magic words 
Situation 
Reason 

Weird(?) magic word for sh to invoke perl under Linux 

Newsgroups: comp.unix.shell,comp.lang.perl.misc,comp.os.linux.misc

: Under Solaris, I always use the following lines in my perl code to
: invoke it:
: #!/bin/sh -- # -*- perl -*- -w
: eval 'exec perl $0 ${1+"$@"}'
:   if 0;

If you use

#! /usr/bin/env perl

as the first line of your script, then it will be run using whatever copy of perl is found first on your path. I know this trick works on both RH Linux and Solaris, and believe that it will work on most Unix systems.

The problem with using

#! /usr/bin/perl

for the first line, as suggested by some others, is that perl is often installed in /usr/local/bin/perl instead. (if it doesn't come with the system and is installed later by the sys admin).

Paul Hughett

documented on: 2001.03.22 Thu 17:04:22