Bash script not working

I am very new to bash scripting but have learned a lot over the past several days. I was given this script that uses a program called mc2xml to download adn xml file that then gets loaded into EyeTV. My problem is the path in the cd commads thinks the path starts with ers instead of /Users. Also the ping command recieved no packets. These commands work fine if I enter them directly into Terminal.


Script:


#!/bin/bash

MC2XML="/Users/ericphil2/Scripts/mc2xml"

XMLTV="/Users/ericphil2/Scripts/xmltv.xml"

#Set the working directory

cd /Users/ericphil2/Scripts

#Check for internet connection

ping -q -c 1 -t 5 google.com

if [ $? -eq 0 ]; then

#Get new schedule

$MC2XML -J -c us -g 14519

#Reload EyeTV with the file

echo "in if statement"

open -a EyeTV $XMLTV

fi


Here is the response from Terminal:


[MacPro:~/Scripts] ericphil2% sh ./test2.sh

Hello World

/Users/ericphil2/Scripts/mc2xml

/Users/ericphil2/Scripts/xmltv.xml

: No such file or directoryers/ericphil2/Scripts

PING google.com\013 (198.105.244.228): 56 data bytes


--- google.com\013 ping statistics ---

1 packets transmitted, 0 packets received, 100.0% packet loss

./test2.sh: line 18: syntax error: unexpected end of file

[MacPro:~/Scripts] ericphil2% sh ./test2.sh

: No such file or directoryers/ericphil2/Scripts

PING google.com\013 (198.105.244.228): 56 data bytes


--- google.com\013 ping statistics ---

1 packets transmitted, 0 packets received, 100.0% packet loss

./test2.sh: line 15: syntax error: unexpected end of file

[MacPro:~/Scripts] ericphil2%

Accepted Reply

To answer my own question it was carraige returns in the code. Here is the fix


tr -d '\r' <FileWithCarraigeReturns> FileWithOutCarraigeReturns

Replies

Let me try to be more specific. I can get rid of the ping and if statements since mc2XML just wont be able to get the file but nothing alerts me to no internet connection. When I do this and run the script in Terminal I get errors from the cd /Users/ericphil2/Scripts, $MC2XML -J -c us -g 14519 and open -a EyeTV $XMLTV lines all come back saying directory of file do not exist. To ensure I was not typing something wrong I dragged the directory of file onto the editor to allow it to build the appropriate paths. Any idea why it wont see the paths correctly?

To answer my own question it was carraige returns in the code. Here is the fix


tr -d '\r' <FileWithCarraigeReturns> FileWithOutCarraigeReturns