Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I also got above error; so I was looking going through this topic.
Just to add -- this error also comes when no perl is installed on your system.
While trying command "perl -i -pe's/\r$//;' <file name here>" I come to know about this Thanks!!!
or trying to ftp the script from a Windows-based machine to a Unix-based machine while NOT under binary mode will do the job
Thanks to both wbrummet and timmeke!
I had this issue which drove me nuts. I was familiar with dos2unix and the variations of line feeds...but still nothing fixed it and it still didn't execute.
As it turns out, the script I was trying to execute was on a external USB drive mounted with the 'noexec' option. doh! Move the script to local hard drive (mounted without 'noexec' obviously) and everything works...
I have run into this problem many times when editing scripts on a windows based system then FTP'ing them onto my servers. I simple Perl command always seems to clear up the problem. Try the following command on your text file then try and run it.
perl -i -pe's/\r$//;' <file name here>
Thanks. This script worked for me as well. What does it do?
A lot of the commands (using tr, perl, ...) posted here all do pretty much the same as the "dos2unix" utility mentioned. Please use this utility, as it was specifically created for this CR\LF issue.
Yes, dos2unix may be preferred, but it's not always installed. I ran into this issue today with a server that did not have a dos2unix command but did have perl installed, so the perl one liner here saved me a bit of time.
We should encourage alternative solutions, not discourage them.
I had the same problem as everybody who has been asking here.
I tried some of the suggested ideas but still no success
The way I have fixed it is by removing the top line
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.