Shell script syntax error: unexpected end of line

Posted by user1557674 on Stack Overflow See other posts from Stack Overflow or by user1557674
Published on 2012-10-05T21:11:38Z Indexed on 2012/10/05 21:37 UTC
Read the original article Hit count: 132

Filed under:
|
|

I wrote a simple shell script to check for the existence of a xml file and if it exists, then rename an old xml file to be backup and then move the new xml file to where the old xml file was stored.

#!/bin/sh    

oldFile="/Documents/sampleFolder/sampleFile.xml"
newFile="/Documents/sampleFile.xml"
backupFileName="/Documents/sampleFolder/sampleFile2.backup"
oldFileLocation="/Documents/sampleFolder"

if [ -f "$newFile" ] ; then
    echo "File found"
    #Rename old file
    mv $oldFile $backupFileName
    #move new file to old file's location
    mv $newFile $oldFileLocation
else
    echo "File not found, do nothing"
fi   

However, every time I try to run the script, I get 4 command not found messages and a syntax error: unexpected end of file. Any suggestions on why I get these command not found errors or the unexpected end of file? I double checked that I closed all my double quotes, I have code highlight :)

EDIT: output from running script:

: command not found: 
: command not found: 
: command not found1: 
: command not found6: 
replaceXML.sh: line 26: syntax error: unexpected end of file

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell