Works from bash prompt, but not from script!

I'm trying to use unison from bash on windows with cygwin. I don't know if this is a cygwin question, bash question or unison question. Since I always get reprimanded by the cygwin mailing list for assuming it is a cygwin problem, I'll assume it is a bash question.

The following commands work from the bash command prompt:

cp /cygdrive/c/.emacs .
cp /cygdrive/c/.viper .
ls
unison "/cygdrive/c/busines" "busines" 

However, when I put them in a bash script and chmod +x backup.bash I get the following errors:

Incidentally, I'm editing using emacs and emacs is not showing any control characters. So I'm mystified where bash is complaining about '\r'!

Also, the line numbers don't align correctly because I deleted a lot of comments.

What am I doing wrong?
Thanks,
Siegfried

please post the whole script.... and use "set -xv" in your script to see more debug information at runtime...

Really should include the shebang #!/bin/bash, or what have you, in all your scripts. Putting an extension of .bash doesn't do anything in this case.

I just when back to the script file and noticed that someone has inserted ^M at the end of each line! Hmmm... This could explain some of those error messages. While this is still a bash question, it might be a windows problem. Is there a way to make bash tolerate the ^M?

Here is the entire file:

#!/usr/bin/bash
#
# Begin commands to execute this file using bash with bash
# chmod +x backup.bash
# ./backup.bash
# End commands to execute this file using bash with bash
#
# $Log$
#
set -xv
cp /cygdrive/c/.emacs .
cp /cygdrive/c/.viper .
ls

#pushd Documents\ and\ Settings/Administrator
#unison "/cygdrive/c/Documents and Settings/Administrator/.m2" .m2 
#unison "/cygdrive/c/Documents and Settings/Administrator/.maven" .maven 
#unison "/cygdrive/c/Documents and Settings/Administrator/.middlegen" .middlegen 
#unison "/cygdrive/c/Documents and Settings/Administrator/.mysqlcc" .mysqlcc 
#unison "/cygdrive/c/Documents and Settings/Administrator/.squirrel-sql" .squirrel-sql 
#unison "/cygdrive/c/Documents and Settings/Administrator/Application Data" Application Data 
#unison "/cygdrive/c/Documents and Settings/Administrator/Bluetooth Software" Bluetooth Software 
#unison "/cygdrive/c/Documents and Settings/Administrator/Contacts" Contacts 
#unison "/cygdrive/c/Documents and Settings/Administrator/Desktop" Desktop 
#unison "/cygdrive/c/Documents and Settings/Administrator/Favorites" Favorites 
#unison "/cygdrive/c/Documents and Settings/Administrator/Incomplete" Incomplete 
#unison "/cygdrive/c/Documents and Settings/Administrator/Local Settings" Local Settings 
#unison "/cygdrive/c/Documents and Settings/Administrator/My Documents" My Documents 
#unison "/cygdrive/c/Documents and Settings/Administrator/NTUSER.DAT" NTUSER.DAT 
#unison "/cygdrive/c/Documents and Settings/Administrator/NetHood" NetHood 
#unison "/cygdrive/c/Documents and Settings/Administrator/PUTTY.RND" PUTTY.RND 
#unison "/cygdrive/c/Documents and Settings/Administrator/java6" java6 
#unison "/cygdrive/c/Documents and Settings/Administrator/runtime-EclipseApplication" runtime-EclipseApplication 
#unison "/cygdrive/c/Documents and Settings/Administrator/ssh" ssh 
#unison "/cygdrive/c/Documents and Settings/Administrator/workspace" workspace 
#popd

unison "/cygdrive/c/busines" "busines" 
#unison "/cygdrive/c/C++ Labs" "C++ Labs"
#unison "/cygdrive/c/CVS" "CVS" 
#unison "/cygdrive/c/CVS_2006" "CVS_2006" 
#unison "/cygdrive/c/CVS_Books" "CVS_Books" 
#unison "/cygdrive/c/CVS_Bugzilla_2_14_5" "CVS_Bugzilla_2_14_5" 
#unison "/cygdrive/c/CVS_C++" "CVS_C++" 
#unison "/cygdrive/c/CVS_Config" "CVS_Config" 
#unison "/cygdrive/c/CVS_Diary" "CVS_Diary" 
#unison "/cygdrive/c/CVS_GMM" "CVS_GMM" 
#unison "/cygdrive/c/CVS_LectureNotes" "CVS_LectureNotes" 
#unison "/cygdrive/c/CVS_Loki" "CVS_Loki" 
#unison "/cygdrive/c/CVS_OOP" "CVS_OOP" 
#unison "/cygdrive/c/CVS_OpenSource" "CVS_OpenSource" 
#unison "/cygdrive/c/CVS_Pillar" "CVS_Pillar" 
#unison "/cygdrive/c/CVS_Pillar_XSLT" "CVS_Pillar_XSLT" 
#unison "/cygdrive/c/CVS_ProSpring" "CVS_ProSpring" 
#unison "/cygdrive/c/CVS_Tomcat" "CVS_Tomcat" 
#unison "/cygdrive/c/CVS_WinOOP" "CVS_WinOOP" 
#unison "/cygdrive/c/CVS_YahooFinanceBot" "CVS_YahooFinanceBot" 
#unison "/cygdrive/c/CVSBusiness" "CVSBusiness" 
#unison "/cygdrive/c/CVSNT" "CVSNT" 
#unison "/cygdrive/c/CVSROOT" "CVSROOT" 
#unison "/cygdrive/c/dev" "dev" 
#unison "/cygdrive/c/DiskSpace" "DiskSpace" 
#unison "/cygdrive/c/Documents and Settings" "Documents and Settings" 
#unison "/cygdrive/c/emacs" "emacs" 
#unison "/cygdrive/c/inetpub" "inetpub" 
#unison "/cygdrive/c/OOP" "OOP" 
#unison "/cygdrive/c/WinOOP" "WinOOP" 

Here are all the error messages again after I ran it again after remove the ^M at the end of each line.

use "dos2unix" to delete the ^M

Thanks for the good infos.

Thanks. Good infos

Yup-- that worked. Emacs was telling me there were no \r but apparently there were because dos2unix worked (even on windows).

Thanks,
Siegfried