ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Rep:
Shell scripts in Windows Cygwin
Just wondering if anyone else writes shell/BASH scripts using Cygwin in Windows? For some reason, my backup script, which works fine in Linux, does not work in Cygwin under Windows. It seems to stick in random characters and letters in my script, which causes it to fail. Anyone else notice any irregularities with Cygwin in Windows??
Unfortunately I can't copy/paste the error, but it basically starts changing my paths by adding extra "\" and "r" in there. This script works 100% fine in Linux, but not Cygwin (paths are changed appropriately, of course). Keep in mind that this works fine when I manually type it in Cygwin without the variables, but when I launch it from a batch script in DOS then it gets all messed up.
If you are using binary mounts on cygwin (which is the default and also recommended), your script must use unix style line endings. Run the command d2u on your scripts.
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
Quote:
Originally Posted by allend
How are you editing your scripts? \r looks suspiciously like Windows carriage return.
I am using either notepad.exe or the simple 'edit' command in DOS. I don't see any weird characters in my script.
Quote:
Originally Posted by Hivemind
If you are using binary mounts on cygwin (which is the default and also recommended), your script must use unix style line endings. Run the command d2u on your scripts.
What the heck is a binary mount? What are unix style endings?
See here: http://en.wikipedia.org/wiki/Newline
Basically, dos/windows uses 2 (invisible) chars to denote a line ending (cr & lf), Unix/Linux uses only 1 (lf).
These are represented in explicit coding as \r\n (MS), \n (Linux).
See also: http://www.asciitable.com/
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
Thanks for the info! So if these 2 characters are invisible, how would I know they are there other than seeing the output error? I am seeing the \r in my path, and that does explain why it is magically showing up. Are there other editors in Windows I can use that won't put these invisible characters?
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
Thank you, all! It's frustrating to see that there are those small nuisances that can make or break a script. I'm also glad that I'm not the only one that is going crazy over this and that it is documented
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
Sorry for the long delays but I was out on a 2-week vacation!
I fixed the problem by using and installing the Cygwin nano editor. I had to go to the end of each line and press the DEL key to get rid of the hidden "\r". My scripts work fine now. So my future advice to others using Cygwin is to NOT use the Windows Notepad or Wordpad editor to write your scripts.
I'm a Windows guy working in a Linux world. So I wrote my .sh script in a 'Notepad.exe' before FTP'ing it up to my linux servers.
I spent about 8 hours on this problem, so sad. I opened the file in gedit (centos), and just went to the begining of each line and hit 'delete' twice (if you have to hit it twice you know you have the problem) the rentered the "return".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.