The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 12:25 PM
Error: `mv olddir/ newdir/ ` never works on new version of bash? meili100 UNIX for Dummies Questions & Answers 5 02-20-2008 04:56 PM
perl - how come this script works? mjays Shell Programming and Scripting 3 09-17-2007 10:50 AM
substring command works but only in BASH shell edwardtk11 Shell Programming and Scripting 2 06-27-2007 05:25 PM
customize my prompt in bash yankee428 UNIX for Dummies Questions & Answers 2 06-23-2005 02:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2008
siegfried siegfried is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 91
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:

Code:
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:

Quote:
chmod +x backup.bash
./backup.bash

./backup.bash: line 12: $'ls\r': command not found
./backup.bash: line 13: $'\r': command not found
./backup.bash: line 36: $'\r': command not found
Error: Ill-formed name of file in UNISON directory: /cygdrive/c/busines

Compilation exited abnormally with code 3 at Sat Feb 09 13:51:56
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
  #2 (permalink)  
Old 02-09-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,953
please post the whole script.... and use "set -xv" in your script to see more debug information at runtime...
  #3 (permalink)  
Old 02-09-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
Quote:
Originally Posted by siegfried View Post
What am I doing wrong?
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.
  #4 (permalink)  
Old 02-09-2008
siegfried siegfried is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 91
Where do those ^M keep coming from?

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:
Code:
#!/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.
Quote:
bash-3.2$ set -xv
bash-3.2$ ./backup.bash
./backup.bash
+ ./backup.bash
: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
./backup.bash: line 13: $'ls\r': command not found
./backup.bash: line 14: $'\r': command not found
./backup.bash: line 37: $'\r': command not found
Error: Ill-formed name of file in UNISON directory: /cygdrive/c/busines
bash-3.2$
  #5 (permalink)  
Old 02-09-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,953
use "dos2unix" to delete the ^M
  #6 (permalink)  
Old 02-09-2008
sinangunay sinangunay is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
Thanks for the good infos.
  #7 (permalink)  
Old 02-09-2008
tahsinaltay tahsinaltay is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 7
Thanks. Good infos
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0