If you happen to have this kind of error for no reason, please make sure you convert your shell script file to UNIX format using any text editor like Notepad++. Initially it seems like a weird error but yet another valid issue with Cygwin + XP editor.
Here is an example, If you create a script in Notepad++
-------------------------------------------------------------------
#!/bin/bash
#
# My Cygwin weird error
#
clear
echo "Knowledge is Power"
-------------------------------------------------------------------
When you run this script directly from Cygwin (by editing it from Notepad) you might forget to set the file format to Unix. This often result in following error.
-------------------------------------------------------------------
./print_a_line.sh: line 1: $'\r': command not found
Knowledge is Power
-------------------------------------------------------------------
Or,
You can convert them to UNIX format using shell utility dos2unix
So, Thats it! You are set!


23 comments:
January 14, 2009 6:20 PM
Thanks it really helped !!!
March 11, 2009 7:30 AM
lol.. I didn't remember about differences between \n in *nix and windows :D
Thank you ;)
June 10, 2009 4:46 AM
Easiest thing to do:
dos2unix ./*
Will convert all files in the current directory.
July 14, 2009 8:54 PM
If your files are part of a SVN project, you can change the EOL style of the scripts to make them always use LF.
July 26, 2009 5:27 PM
Gracias, estuve todo el día quebrandome la cabeza!!!!! ni siquiera las variables me funcionaban
September 10, 2009 2:04 PM
Thanks, I was doing lot of research around this. Really helped.
October 2, 2009 6:35 AM
Nice tip, thanks a lot dude!
December 2, 2009 6:56 AM
Hello i get this error when trying to make the U_Boot files for any type of processor. I m using WindowsXP, Cygwin and GNUARM. The U_Boot repository i downloaded with standard cofiguration of GIT.
I tried the dos2unix command but it doesnt seem to do anything. Also i am not sure if it is handling recursevly the hundrets of files nad folder i have in the repository. It is not giving any message.
December 2, 2009 7:10 AM
hey i found the error!! git had downloaded the tree with dos ending. I reconfigured git to download with unix ending, and it works. since that command dos2unix didnt work.
March 3, 2010 7:25 PM
Thanks, mate! It really helped me configure Hadoop (on a Windows box so I had to use Cygwin). Just one suggestion though - this page was nigh unreadable with the white font on the grey background. Please change it!
May 9, 2010 7:44 AM
Hello thanks a lot for ur help.
September 8, 2010 2:58 AM
dos2unix FILENAMEGOESHERE works like a charm.
December 31, 2010 3:58 PM
Thanks.. it did help me..
http://tamilnovelsonline.blogspot.com
January 10, 2011 11:13 PM
thanks
January 22, 2011 11:57 PM
This didn't work for me, don't know why.
January 22, 2011 11:58 PM
January 23, 2011 2:08 AM
I ended up saving one of the config files in Unix format, since it had been in Windows format for some reason. Anyway, I still get an error message when I try to run a command to return the Hadoop version:
$ bin/hadoop version
cygwin warning:
MS-DOS style path detected: C:\cygwin\usr\local\hadoop\/build/native
Preferred POSIX equivalent is: /usr/local/hadoop/build/native
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
/usr/local/hadoop/bin/hadoop-config.sh: line 190: C:\jdk1.6.0_18: command not found
Hadoop 0.21.0
Subversion https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.21 -
r 985326
Compiled by tomwhite on Tue Aug 17 01:02:28 EDT 2010
From source with checksum a1aeb15b4854808d152989ba76f90fac
May 8, 2011 2:37 AM
Thanks
May 21, 2011 11:17 PM
i was waiting for this code
June 28, 2011 5:56 PM
Awesome! Thanks for your post.
August 3, 2011 3:34 PM
Thanks! That did the trick for me as well.
January 18, 2012 5:50 PM
To expand on the Notepad++ problem specifically, you can change it by:
Edit -> EOL Conversion -> UNIX Format
February 16, 2012 11:09 PM
Hi, I am trying to Run Shell script using Cygwin and Java. When i run script on command prompt it works fine but when i m running same script it stops where i am doing dos2unix *.* can you tell me how to avoid this. is there any setting which will allow me to run script directly.
Post a Comment