Babun (cygwin) and .sh files. What's wrong?

0

I am trying to execute some really simple script .sh under windows, but I really can't. I am totally beginner about scripting and babun, so I try to explain my problem.

I have 2 files and I need manipulate them with the command sed.

The commands input are :

cd /cygdrive/c/ProgramData/ServerCare/WebGrab_01/

sed -i "15s|.*|  <filename>C:\\\ProgramData\\\ServerCare\\\data\\\xml\\\guide_01.xml</filename>|" WebGrab++.config.xml

cd /cygdrive/c/ProgramData/ServerCare/WebGrab_02/

sed -i "15s|.*|  <filename>C:\\\ProgramData\\\ServerCare\\\data\\\xml\\\guide_02.xml</filename>|" WebGrab++.config.xml

cd /cygdrive/c/ProgramData/ServerCare/WebGrab_01/

sed -i '/<!--02-->/,/<!--19-->/d' WebGrab++.config.xml

cd /cygdrive/c/ProgramData/ServerCare/WebGrab_02/

sed -i '/<!--01-->/,/<!--02-->/d' WebGrab++.config.xml

sed -i '/<!--03-->/,/<!--19-->/d' WebGrab++.config.xml

Sending this commnds one by one everything is ok.

If I add the same commands in one file .sh nothing is working fine. On the shell, when I execute the file I made, I can read all path I am using are wrong. Why if I lunch the commands one by one everything is ok and if I lunch one script not?

This is the file I made cygwin.sh

#!/bin/bash

cd /cygdrive/c/ProgramData/ServerCare/WebGrab_01/
sed -i "15s|.*|  <filename>C:\\\ProgramData\\\ServerCare\\\data\\\xml\\\guide_01.xml</filename>|" WebGrab++.config.xml
cd /cygdrive/c/ProgramData/ServerCare/WebGrab_02/
sed -i "15s|.*|  <filename>C:\\\ProgramData\\\ServerCare\\\data\\\xml\\\guide_02.xml</filename>|" WebGrab++.config.xml
cd /cygdrive/c/ProgramData/ServerCare/WebGrab_01/
sed -i '/<!--02-->/,/<!--19-->/d' WebGrab++.config.xml
cd /cygdrive/c/ProgramData/ServerCare/WebGrab_02/
sed -i '/<!--01-->/,/<!--02-->/d' WebGrab++.config.xml
sed -i '/<!--03-->/,/<!--19-->/d' WebGrab++.config.xml

The errors i recive:

{ bash }  » ./cygwin.sh
/cygdrive/c/ProgramData/ServerCare/data/bash
./cygwin.sh: line 2: $'\r': command not found
: No such file or directoryygdrive/c/ProgramData/ServerCare/WebGrab_01/
: No such file or directoryonfig.xml
: No such file or directoryygdrive/c/ProgramData/ServerCare/WebGrab_02/
: No such file or directoryonfig.xml
: No such file or directoryygdrive/c/ProgramData/ServerCare/WebGrab_01/
: No such file or directoryonfig.xml
: No such file or directoryygdrive/c/ProgramData/ServerCare/WebGrab_02/
: No such file or directoryonfig.xml
 sed: can't read WebGrab++.config.xml: No such file or directory

Also, I need edit the files 2 times a day, is there one way to lunch the file .sh and execute it in inside the shell Babun? I know the way to lunch it automatically under windows 7, but not the way to associate the alternative shell. If I lunch the file .sh and I choose babun to execute it nothing happen.

Thank you in advice to everybody can answer me :)

Thank you DavidPostill to help me about the edit.

Tapiocapioca

Posted 2016-08-30T21:20:34.073

Reputation: 3

1How are we supposed to help when you don't include the commands you are running and the shell file you are having problems with? Please [edit] your question to include this important missing information. Don't forget to include any error messages. – DavidPostill – 2016-08-30T21:36:12.783

Answers

0

the hint is here:

./cygwin.sh: line 2: $'\r': command not found

convert the file from CRLF line termination to LF only termination with

d2u ./cygwin.sh 

On cygwin the d2u command belongs to package dos2unix-7.3.4-1, I assume also babun should have it.

matzeri

Posted 2016-08-30T21:20:34.073

Reputation: 1 662

Really thank you matzeri. It's working great! Do you know also the way to make one .bat file or similar to lunch automatically the file cygwin.sh inside Babun? – Tapiocapioca – 2016-08-31T10:51:13.250

I don't use Babun. Just vanilla Cygwin – matzeri – 2016-08-31T15:40:11.823