Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple shell script in cygwin

Tags:

shell

unix

cygwin

#!/bin/bash
echo 'first line' >foo.xml
echo 'second line' >>foo.xml

I am a total newbie to shell scripting.

I am trying to run the above script in cygwin. I want to be able to write one line after the other to a new file.

However, when I execute the above script, I see the follwoing contents in foo.xml:

second line

The second time I run the script, I see in foo.xml:

second line
second line

and so on.

Also, I see the following error displayed at the command prompt after running the script:

: No such file or directory.xml

I will eventually be running this script on a unix box, I am just trying to develop it using cygwin. So I would appreciate it if you could point out if it is a cygwin oddity and if so, should I avoid trying to use cygwin for development of such scripts?

Thanks in advance.

like image 973
Kapsh Avatar asked Sep 22 '26 23:09

Kapsh


2 Answers

Run dos2unix on your shell script. That will fix the problem.

like image 78
Don Branson Avatar answered Sep 25 '26 18:09

Don Branson


I had the same kind of problem as the original poster: A very simple script file was not working in Cygwin.

Thanks to Don Branson for the clue.
The fix for me was built into the text editor I'm using. (Most programmer's editors have a feature like this.) For example, in my case I'm using Notepad++, which has a menu item to convert the file line endings to Unix-style. From the menu: [Edit]->[EOL Conversion]->[Unix (LF)]

Then the script behaved as expected.

like image 22
Robert Blansett Avatar answered Sep 25 '26 20:09

Robert Blansett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!