Script shows a bad interpreter and will not start

I was sent a perl script in the mail and asked to run it. I put it on my local drive as it is, but when I tried to run the script, it showed me

/usr/bin/perl^M: bad interpreter: No such file or directory 

I checked and usr / bin / has perl. I'm not sure what is wrong. I checked a little and looked like I was missing spaces or something like that. I tried adding them at the end of usr / bin / perl and at the end of the file, but that didn't help either. I even tried using dos2unix

 dos2unix oldfile newfile 

'dos2unix' not found. This is on MacOSX. May I also mention that I am in my mac using my Windows machine at home.

+2
perl
source share
4 answers

In the absence of dos2unix you can use tr (on Mac OS X) to mark up new DOS / Windows lines:

 tr -d '\r' < old.pl > new.pl 

This will solve the bad interpreter problem.

"Unable to find Gpu.pm in @INC" is another problem. Either you do not have Gpu.pm installed on your Mac (or depending on which computer you are running on, I am confused by your comments), or it is not included in your inclusion path. I do not know what this script is or what it does. A quick look at http://search.cpan.org/ showed nothing.

If you can get this Perl module (presumably from the one who installed oldfile ), you need to make sure that it is in @INC .

+4
source share

You are on the right track. At the end of the script, there are DOS-style lines that are not supported by your kernel.

The solution is to use something to convert new DOS lines to Unix style. dos2unix will supposedly work if you have one, so use something else equivalent.

+9
source share

Do it in vim:

 :%s/^M//g 

save the file and try to run it again

run: vim

when vim opens, go into command mode by pressing escape .... at the command line (:) type: %s/^M//g . This will remove all β€œ^ M” characters from the file.

+3
source share

dos2unix in Perl:

 perl -pi -e 'tr/\r//d' file.txt 
+2
source share

All Articles