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

Thought I had covered all requirements, but apparently not. This is on a new Ubuntu Linux install, Perl v5.14

line 1 of script is #!/usr/bin/perl. Which perl returns that location. Chmod to 744 (-rwxr)

cd to scripts directory, then ./script.pl

error message:

^M: bad interpreter: No such file or directory

What did I miss?

Replies are listed 'Best First'.
Re: executing perl script
by davido (Cardinal) on Mar 08, 2014 at 16:51 UTC

    The file was created on a non-Linux system and uploaded without converting line endings, or if you created the file on your linux system, the editor was in the wrong line-ending mode. Also, isn't the message "/usr/bin/perl^M: bad interpreter: No such file or directory"? It's really important to post complete error messages, as something that might seem irrelevant to you may provide insight into problem that others who are accustomed to seeing error messages can better decipher. After all, if you understood what parts of the message were important you wouldn't need to ask, right? ;)

    In this thread, "/usr/bin/perl^M: bad interpreter:", I really like the statement, "The ^M is the key to the entire problem, it's not something that just can be ignored."

    What that message is really telling you is that your operating system cannot find an interpreter named /usr/bin/perl^M. Windows and DOS terminate text lines with carriage-return (ASCII 13), followed by line-feed (ASCII 10). Linux uses just line-feed to terminate lines. So the shell knows that when it sees #!/usr/bin/perl^J, where ^J is the ASCII-10 line feed at the end, that line feed character can be stripped away from the text, and it can go looking for an interpreter named /usr/bin/perl.

    But in your case, your shell is finding #!/usr/bin/perl^M^J (ASCII 13, ASCII 10 at the end of line), it again gladly ignores the linefeed, but thinks that you are looking for a program named #!/usr/bin/perl^M, where "^M" represents ASCII 13, the carriage return character. It's unlikely that you have a Perl interpreter named perl^M, and since you don't, your shell complains to you.

    There are utilities that can convert DOS/Windows line endings to Linux line endings. Also FTP clients, in "text" mode will handle the conversion for you silently. And some editors can be configured to generate output with linefeeds as line terminators even when edited on carriage-return/line-feed operating systems. The easiest mechanism is to just set your FTP client to do the conversions for you. ...or develop in an environment that matches your target deployment operating system.


    Dave

Re: executing perl script
by karlgoethebier (Abbot) on Mar 08, 2014 at 16:50 UTC
    "What did I miss?"

    dos2unix script.pl?

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Re: executing perl script
by Lennotoecom (Pilgrim) on Mar 08, 2014 at 20:14 UTC
    Have you tried
    perl -i -pe 'y/\r//d' script.pl
    ?
Re: executing perl script
by toolic (Bishop) on Mar 08, 2014 at 16:52 UTC
Re: executing perl script
by pvaldes (Chaplain) on Mar 08, 2014 at 16:51 UTC
    use strict; use warnings?