LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2014, 01:24 PM   #1
Zippy1970
Member
 
Registered: Sep 2007
Posts: 119

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


I just installed Arch Linux on a Raspberry Pi and wrote a little perl script. But whenever I try to run the script, I get the following error:

Code:
/usr/bin/perl^M: bad interpreter: No such file or directory
Yes, I know that usually happens when you transfer a file from a Windows system to a Linux system (since Windows uses CRLF pairs, and Linux only LF as line endings). But the problem here is, that there is no CR at the end of the lines.

I checked the file (on Linux) in a Hex Editor and it confirmed there are only LFs (0x0A).

So what/who is adding the CRs? Is it bash? How do I get rid of them? I know about dos2unix, but that doesn't help since there aren't any CRs in the file in the first place...
 
Old 09-25-2014, 02:00 PM   #2
Zippy1970
Member
 
Registered: Sep 2007
Posts: 119

Original Poster
Rep: Reputation: 17
To answer my own question: it was caused by a number of reasons:

First of all, I use vsftpd to transfer the file from a Windows machine to the Arch Linux machine. I specifically used ASCII mode for the transfer. vsftp by default ignores ASCII file transfer requests and does a binary transfer instead. I did not know that.

The reason I didn't see those CRs was because I use JOE as my editor (it has a HEX edit mode). And JOE by default automatically translates CRLF to LF when reading, and translates it back to CRLF when writing. I did not know that either (and is new for me since I've installed JOE on many, many machines before).

So in short, I had to tell vsftpd to accept ASCII transfers as well, and tell JOE not to automatically translate CRLF to LF and vice versa.
 
Old 09-26-2014, 09:30 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,868
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
off: here is an adcr/rmcr program I wrote some years ago
 
Old 09-26-2014, 09:32 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Zippy1970 View Post
To answer my own question: it was caused by a number of reasons:

First of all, I use vsftpd to transfer the file from a Windows machine to the Arch Linux machine. I specifically used ASCII mode for the transfer. vsftp by default ignores ASCII file transfer requests and does a binary transfer instead. I did not know that.

The reason I didn't see those CRs was because I use JOE as my editor (it has a HEX edit mode). And JOE by default automatically translates CRLF to LF when reading, and translates it back to CRLF when writing. I did not know that either (and is new for me since I've installed JOE on many, many machines before).

So in short, I had to tell vsftpd to accept ASCII transfers as well, and tell JOE not to automatically translate CRLF to LF and vice versa.
thanks for the update. but it doesnt explain why dos2unix didnt work ?
 
Old 09-26-2014, 12:54 PM   #5
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
I always simply do
Code:
sed -i -e 's/<ctrl-v><ctrl-m>//g'
removes that silly newline thing as well... and by preference I never use windows, which helps reduce the amount of times I need this :-)
 
Old 09-26-2014, 01:20 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
pfe32 -a free single executable for Windows does Linux Files very well.
 
Old 09-28-2014, 08:44 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Use "file" to check if it's a problem, and "dos2unix" to fix it. Easy peasy.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or director irlogo Red Hat 5 03-12-2012 04:38 AM
/usr/bin/perl^M: bad interpreter: No such file or directory colindek Ubuntu 17 12-13-2011 09:32 AM
/usr/bin/perl^M: bad interpreter: No such file or directory colindek Linux - Newbie 8 12-12-2011 05:23 PM
[SOLVED] bash: /usr/local/bin/xdsi: /usr/bin/wish: bad interpreter: No such file or directory Berwhale Linux - Newbie 2 09-15-2011 02:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration