2

I was sent a perl script over mail and asked to run it .I placed it on my local drive as is but when I tried to run the script it shows me

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

I checked and usr/bin/ does have perl in there .I am not sure what is wrong.I checked a bit and looks like I am missing some spaces or something ..I tried adding those at the end of usr/bin/perl and at the end of the file but that didnt help either. I even tried to use dos2unix

dos2unix oldfile newfile

'dos2unix' not found.This is on MacOSX. Might I also mention that I am sshing into my mac using my windows machine at home.

4 Answers 4

9

You're on the right track. Your script has DOS style newlines at the end, which is not supported by your kernel.

The solution is to use something to convert the DOS newlines to Unix style. dos2unix would presumably work if you had it, so use something else equivalent.

5
  • Can you tell me where to get dos2unix? I mean I downloaded it from sourgeforge then unzip it and copy over dos2unix.exe to say dos2unix.exe oldfile newfile .It says -bash: ./dos2unix.exe: cannot execute binary file
    – Manish
    Commented Dec 19, 2011 at 2:43
  • 3
    You downloaded a Windows executable to your Mac and it didn't work?
    – johnsyweb
    Commented Dec 19, 2011 at 2:56
  • Alright I go to C:\Documents and Settings\User\My Documents\Downloads\dos2unix-5.3.1-win32\bin and say dos2unix oldfile newfile .It says newfile no such file or directory .I would expect the command to make the new file ..right?
    – Manish
    Commented Dec 19, 2011 at 3:03
  • But you said, "'dos2unix' not found.This is on MacOSX.". That is not a Mac OS X path!
    – johnsyweb
    Commented Dec 19, 2011 at 3:25
  • No earlier one I tried on MacOSX and then I also tried converting on my windows
    – Manish
    Commented Dec 19, 2011 at 4:58
4

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

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

This will solve the "bad interpreter" issue.

"Can't locate Gpu.pm in @INC" is a different issue. Either you don't have Gpu.pm installed on your Mac (or whichever computer on which you are running this, I'm confused by your comments) or it's not in your include path. I don't who what that script is or what it does. A quick look on https://search.cpan.org/ revealed nothing.

If you can get that Perl module (presumably from whoever supplied oldfile), you'll have to ensure it is in @INC.

4
  • Tried this too .It fails also saying Can't locate Gpu.pm in @INC
    – Manish
    Commented Dec 19, 2011 at 2:42
  • That is a different issue. You are missing a Perl module called "Gpu.pm". I don't know what that is or what it does, sorry.
    – johnsyweb
    Commented Dec 19, 2011 at 2:51
  • your problem now is that your don't have the following perl module on your system "Gpu.pm". You need to use cpan to download it Commented Dec 19, 2011 at 2:55
  • @ennuikiller: Gpu.pm is in CPAN? Do you have a URI for that?
    – johnsyweb
    Commented Dec 19, 2011 at 2:57
3

Do this in vim:

:%s/^M//g

save the file and try running it again

execute: vim

when vim opens go to command mode by hitting the escape key .... at the command prompt (:) type: %s/^M//g. This will remove all "^M" characters from the file.

6
  • Can you explain a bit more? where do I add this ?
    – Manish
    Commented Dec 19, 2011 at 2:41
  • still see the pattern not found thingy .Just to be sure there is no space anywhere above in %s/^M//g right
    – Manish
    Commented Dec 19, 2011 at 2:55
  • If you ran this after running tr, then you've already got rid of the DOS newlines so there's nothing to do!
    – johnsyweb
    Commented Dec 19, 2011 at 2:55
  • But that would have been saved in the new file right? This old file should still have the ^M characters
    – Manish
    Commented Dec 19, 2011 at 2:56
  • 1
    @Manish: You probably want to Ctrl+V Ctrl+M to get a raw CR into your :%s/^M//g inside vim. Commented Dec 19, 2011 at 3:17
2

dos2unix in Perl:

perl -pi -e 'tr/\r//d' file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.