MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
November
Sun Mon Tue Wed Thu Fri Sat
   
28      
2005
Months
Nov


Mon, Nov 28, 2005 11:07 pm

Bad interpreter: No such file or directory

If you receive the message "bad interpreter: No such file or directory" when attempting to execute a Perl script, it may because the path to Perl is incorrect in the script. You can check the location of the Perl executable with which perl. Some common locations for Perl are shown below:

/uisr/bin/perl
/usr/sbin/perl
/usr/local/bin/perl
/usr/bin/perl5
/usr/local/bin/perl5

The first line of the Perl script should point to the location revealed for Perl by which perl. E.g., if Perl is in /usr/bin, you should see the following line as the first line of the Perl script.

#!/usr/bin/perl

But, if the path is listed correctly in the script, another check to make is that you aren't using a Perl file in DOS format. For instance, if the file was created on a Windows system and was transferred to a Unix or Linux system in binary mode rather than ASCII mode, then the lines in the file may not be terminated properly for the Linux or Unix system. For a Linux or Unix system, each line should be terminated with a newline character, i.e. hexadecimal 0A. A DOS formatted file, i.e. the text file type you would find on a Windows system will use both a carriage return (CR) and line feed (LF), i.e. a hexadecimal 0D followed by a hexadecimal 0A.

If you attempt to run a Perl script which uses the DOS format on a Unix or Linux system, you will likely get the error message ": bad interpreter: No such file or directory"

You can check the line endins with the hexdump command. Below are two example files test.pl and test2.pl, which are identical, except for the line endings.


# hexdump -C test.pl
00000000  23 21 2f 75 73 72 2f 62  69 6e 2f 70 65 72 6c 0d  |#!/usr/bin/perl.|
00000010  0a 0d 0a 70 72 69 6e 74  20 22 68 65 6c 6c 6f 5c  |...print "hello\|
00000020  6e 22 3b 0d 0a                                    |n";..|
00000025
# hexdump -C test2.pl
00000000  23 21 2f 75 73 72 2f 62  69 6e 2f 70 65 72 6c 0a  |#!/usr/bin/perl.|
00000010  0a 70 72 69 6e 74 20 22  68 65 6c 6c 6f 5c 6e 22  |.print "hello\n"|
00000020  3b 0a 0a                                          |;..|
00000023

If you examined the code in a regular editor, you would see the following lines in each file:

#!/usr/bin/perl

print "hello\n";

But, if you tried to execute them on a Unix or Linux system, you would see different results.

# ./test.pl
: bad interpreter: No such file or directory
# ./test2.pl
hello

You can convert a file, e.g. test.pl, to Unix text file format with dos2unix, which is a DOS/MAC to UNIX text file format converter.

dos2unix test.pl

References:

  1. Perl & CGI Tutorial: Your First CGI Script
  2. dos2unix

[/languages/perl] permanent link

Mon, Nov 28, 2005 8:07 pm

List Perl Modules

I encountered a problem with a Perl module not being found when I tried to run a Perl script that required it, even though I thought I had successfully installed that module. I wanted to see a list of all the Perl modules installed on the system. I found a free Perl script list-modules.pl at http://webnet77.com/scripts/list-modules/, which will list all of the Perl modules installed on the system on which it is run. The output of the program is an HTML page listing the modules. So you can put the script in a cgi-bin directory on your Web server to make the information accessible over the web. On a Linux or Unix system, you should use chmod 755 list-modules.pl to first make the file executable.

I did encounter one problem when I first attempted to run the script. I kept getting a ": bad interpreter: No such file or directory" message whenever I tried to run it. That usually indicates the path to the Perl interpreter in the first line of the file is incorrect. When I checked it, I found it was "#!/usr/bin/perl". When I checked Perl's location, I saw it was in /usr/bin/perl.

which perl
/usr/bin/perl

It took me a few minutes to realize that when I downloaded list-modules.zip from the Webnet77 page and then unzipped it on my Linux server, that the extracted Perl file, list-modules.pl, was in DOS format, i.e. the end of every line was terminated with a carriage return and line feed (hexadecimal 0D and 0A) rather than just a line feed (hexadecimal 0A), which is how newlines are indicated on Unix and Linux systems. I spotted the problem when I used hexdump -C list-modules.pl. I used dos2unix list-modules.pl to convert the file to the Unix text file format. I was then able to successfully run the list-modules.pl script.

Download: list-modules.pl

[/languages/perl] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo