Script showing bad interpreter and will not run

前端 未结 4 1653
星月不相逢
星月不相逢 2021-01-21 10:03

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          


        
相关标签:
4条回答
  • 2021-01-21 10:28

    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 http://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.

    0 讨论(0)
  • 2021-01-21 10:39

    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.

    0 讨论(0)
  • 2021-01-21 10:41

    dos2unix in Perl:

    perl -pi -e 'tr/\r//d' file.txt
    
    0 讨论(0)
  • 2021-01-21 10:42

    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.

    0 讨论(0)
提交回复
热议问题