Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

She-bang confusion

by pepik_knize (Scribe)
on Apr 08, 2002 at 18:31 UTC ( #157510=perlquestion: print w/replies, xml ) Need Help??

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

Greetings Monks,

I keep getting this weird error:
": No such file or directory
bash: ./inventory: bad interpreter: No such file or directory

when I remove the -w from #!/usr/bin/perl from the script inventory. If I run any other scripts without flags, it works fine. Here's what I suspect the problem is: inventory was written on a Windows box running cygwin, and I'm modifying and testing it on a Linux laptop (RH 7.2, perl 5.6.0) and desktop (RH 6.2, perl 5.005_03). When I edit it in vim, it displays DOS at the bottom of the screen, so I think it knows something. Are my linux boxes just being snobbish? Does windows put some trailing : to screw with me? If so, why can't I see it/ get rid of it?
Thanks for the enlightenment,

Replies are listed 'Best First'.
Re: She-bang confusion
by Ovid (Cardinal) on Apr 08, 2002 at 18:37 UTC

    There are a couple of possibilities. If you transferred this to the Linux box and didn't deal with the \r\n line ending, you should either have a dos2unix utility, or you can use the following one-liner to correct this:

    perl -pi.bak -e 's/\r\n$/\n/'

    The above will do the conversion. Actually, just stripping the carriage return is probably fine (s/\r//), but if, for some reason, you had a carriage return anywhere else, you might not want to strip those (can't see why you would, though).

    To verify that the carriage return is actually there, though (the above is wasted if it's not):

    cat -vE

    With that cat command, if you see ^M before the final $, then you know you have carriage returns that need to be stripped.


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: She-bang confusion
by grep (Monsignor) on Apr 08, 2002 at 18:35 UTC

    inventory was written on a Windows box running cygwin, and I'm modifying and testing it on a Linux laptop

    You are correct, I see that problem when the line endings are incorrect for the platform. You need to remove the \r from the line endings in *nix (Win \r\n ends a line - *nix \n ends a line). There are several examples on this site.

    The other choice is to trasfer the files via FTP/SFTP/SCP and specifiy them a text/ascii and it will do the line termination conversion for you.

    Unix - where you can throw the manual on the keyboard and actually get a command
Re: She-bang confusion
by extremely (Priest) on Apr 08, 2002 at 18:41 UTC
    In vim type :se ff=unix and then save the file.

    =) dos endings are going to drive you nuts till you learn to move files with ftp and text mode rather than binary mode.

    Or in perl you can fix the file with perl -pi.bak -e 's/\r\n/\n/'

    $you = new YOU;
    honk() if $you->love(perl)

Re: She-bang confusion
by mrbbking (Hermit) on Apr 08, 2002 at 18:39 UTC
Re: She-bang confusion
by perlplexer (Hermit) on Apr 08, 2002 at 18:38 UTC
    The problem may be related to the fact that Windows puts \r\n at the end of each line as opposed to \n (on UNIX). See if you have dos2unix on your Linux box (man dos2unix), use it if you do. If not, you can FTP the file to yourself using ASCII mode and that'll take care of it.

Re: She-bang confusion
by converter (Priest) on Apr 08, 2002 at 18:57 UTC
Re: She-bang confusion
by pepik_knize (Scribe) on Apr 08, 2002 at 18:46 UTC
    dos2unix did it, and I'm glad to see unix2dos will send it back.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://157510]
Approved by Ovid
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2022-08-16 22:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found