Guildencrantz has asked for the wisdom of the Perl Monks concerning the following question:

I'm running Red Hat 7.2 with Perl 5.6.1, if I run a script with: perl script.pl the script runs fine. Unfortunately if I try to simply run the script I get the following error: : bad interpreter: No such file or directory I checked which perl and it returns /usr/bin/perl. The first line of my script is #!/usr/bin/perl.

These scripts are fine under BeOS and Windows.

What's up?

~~Guildencrantz

Edit by dws for title and tag cleanup

Replies are listed 'Best First'.
Re: : bad interpreter: Permission deniedrl
by Zaxo (Archbishop) on Apr 10, 2002 at 01:27 UTC

    Chances are there is a ^M at the end of the shebang line. Try converting the whole file to unix line ends.

    Update: There are lots of ways. You can use system tr, ftp in ASC mode, zip/unzip for a bulk conversion, and any number of specialized unstandardized converters (not to mention awk and sed). Since you're learning perl, I suggest:

    $ perl -pi.bak -e 's/\015//' *.pl
    once you have checked perlrun to see what the flags do.

    After Compline,
    Zaxo

      I'm lazy, so when this happens to me I just add a -w to the shebang line:

      #!/usr/bin/perl -w

      The -w option seems perfectly happy to have a ^M after it. It's not really safe, but for the most part carriage returns won't make any difference at the ends of lines; they're just whitespace to perl anyway.

      Of course, it could make the bugs even more mysterious...

      Ah, this does look like the problem. I typed a script in my Linux emacs install and it works fine. How do I just convert a file to Unix line ends though? I don't really want to retype all my scripts. ~~Guildencrantz
        use a program called dos2unix (in Redhat and available for most *nix's).

        "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: bad interpreter: Permission denied
by Anonymous Monk on Mar 08, 2010 at 18:49 UTC
    XD It was that last bit of advice that helped me, which ironically was posted very recently in such an old thread—just in time to come to my rescue! A quick 'mount' showed the partition the script was on was mounted with 'noexec'. I really should have thought of that before, but for whatever reason, I didn't. Anyway, thanks a bunch :)
Re: bad interpreter: Permission denied
by Anonymous Monk on Feb 20, 2010 at 22:15 UTC
    This can also be due to the partition being mounted noexec.
Re: bad interpreter: Permission denied
by Anonymous Monk on Mar 09, 2010 at 01:07 UTC
    XD It was that last bit of advice that helped, which ironically was posted very recently in such an old thread—just in time to come to my rescue! A quick 'mount' showed the partition the script was on was mounted with 'noexec'.