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/sholdFile='/Documents/sampleFolder/sampleFile.xml'newFile='/Documents/sampleFile.xml'backupFileName='/Documents/sampleFolder/sampleFile2.backup'oldFileLocation='/Documents/sampleFolder'if -f '$newFile' ; thenecho 'File found'#Rename old filemv $oldFile $backupFileName#move new file to old file's locationmv $newFile $oldFileLocationelseecho 'File not found, do nothing'fiHowever, 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. I believe you're running on Cygwin.
![]()
There's more to the error messages than what you're seeing:: command not found:: command not found:: command not found1:: command not found6:replaceXML.sh: line 26: syntax error: unexpected end of fileYou probably used a Windows editor to create the script file, which means it uses Windows-style CR-LF ( 'rn') line endings, rather than Unix-style LF ( 'n') line endings. Some programs under Cygwin can handle either form, but the shell doesn't.For example, the line that looks like thenlooks to the shell like then^Mwhere ^M is the ASCII CR character. This would actually be a valid command name if it existed, but it doesn't, so the shell complains: then^M: command not foundBut printing the CR character causes the cursor to go back to the beginning of the line, so everthing before the: is overwritten.You're getting the 'unexpected end of file' message because the shell never saw a fi to match the if.You can use the dos2unix command to fix the line endings. Be sure to read the man page ( man dos2unix); unlike most text filters, dos2unix replaces its input file rather than writing to stdout. I can't really see anything wrong with your code apart from then not being in a legal place for older shells. Also notice the quotes around arguments to mv (but that should not be a problem if the files are named properly).Try this: #!/bin/sholdFile='/Documents/sampleFolder/sampleFile.xml'newFile='/Documents/sampleFile.xml'backupFileName='/Documents/sampleFolder/sampleFile2.backup'oldFileLocation='/Documents/sampleFolder'if -f '$newFile' thenecho 'File found'mv '$oldFile' '$backupFileName'mv '$newFile' '$oldFileLocation'elseecho 'File not found, do nothing'fiPS: verify that /bin/sh is (or points to) a bourne based shell.
![]()
Feb 26, 2014 - To fix a NAT issue, you have to consider multiple factors that can cause it. Forwarding, opening pinholes through the firewall, NAT rules, virtual server or something else. That must be considered when attempting to solve a NAT error. (Tools-Options-Plugins-UPnP) and try the nat/firewall test again.
Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |