Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:45:44+00:00 2026-06-12T17:45:44+00:00

I wrote a simple shell script to check for the existence of a xml

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:45:45+00:00Added an answer on June 12, 2026 at 5:45 pm

    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 file
    

    You probably used a Windows editor to create the script file, which means it uses Windows-style CR-LF ("\r\n") 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

    then
    

    looks to the shell like

    then^M
    

    where ^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 found
    

    But 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify this very simple shell script I wrote to check if
I wrote a simple XML file and a DTD file including an entity, but
I wrote a simple PHP shell script which parses files and outputs certain element.
I wrote a super simple bash script to get me into a python shell
I am new to linux and its shell programming. I wrote a shell script
I wrote down on a simple text file the script I have to run
I have wrote a simple shell script where I have only mentioned the following
I wrote a simple shell script to get the version of Perl modules installed
I'm using msysgit on Windows and wrote a simple shell script that I would
I wrote an HTML page with JavaScript, a PHP file and a shell script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.