Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute perl in command line without specifying perl in UNIX

There is a similar question about Windows, but it won't work for Unix based computers (OS X specifically).

I want to type the name of a file, say example.pl or example.pl parametertext.txt, and have it know to execute perl.

I specified #!/usr/bin/perl in the file so it can find the executable. Instead, I get the message:

bash: example.pl: command not found
like image 345
Chris Avatar asked Jan 25 '12 19:01

Chris


People also ask

How do I run a perl command in Unix?

at the top of your perl script, mark the script as executable with the UNIX chmod command, and execute the perl program by simply typing its name at a UNIX prompt.


1 Answers

You can do it this way,

  1. Find the interpreter/executors path. In this case its /usr/bin/perl or /usr/bin/env perl
  2. Add it to the first line of the file as #!/usr/bin/perl.
  3. Give execute permission to the file chmod +x example.pl

Now it will run

    $ ./example.pl
like image 71
Shiplu Mokaddim Avatar answered Sep 18 '22 13:09

Shiplu Mokaddim