No such file or directory error

I am new to shell scripting so I assume there is something basic I am missing but I have not been able to figure it out. When I run the following code from a script it can't find the paths to the directory or files. I can literally cut and paste the commands into terminal and they work fine. Why can't these paths be found when run from a script? I have done chmod 755 getup.sh.

#!/bin/bash
MC2XML="/Users/ericphil2/Scripts/mc2xml"
XMLTV="/Users/ericphil2/Scripts/xmltv.xml"
#Set the working directory
cd /Users/ericphil2/Scripts
#Get new schedule
	$MC2XML -J -c us -g 14519
#Reload EyeTV with the file
	open -a EyeTV $XMLTV

This the response from running the script:

[MacPro:~/Scripts] ericphil2% sh ./getepg.sh
: No such file or directorysers/ericphil2/Scripts
: No such file or directory/ericphil2/Scripts/mc2xml
 does not exist.ericphil2/Scripts/

My guess is your script contains carriage return characters. Perhaps it has been edited on a Windows host?
You can remove them with a dos2unix utility if present or with the following command:

tr -d '\r' < oldfile > newfile
2 Likes

Thanks, tr fixed the problem. I now have the script running daily with a launch agent.