1

Problem using this script: Ubuntu gives the following error $'\r': command not found

#what to backup
backup_files="/home/minecraft/multicraft/jar"

#where to backup to
dest="/"

#create archive filename
day=$(date +%F)
#hostname=$(Set a hostname)
archive_file=$day.tgz

#print start status mesage
echo "Backing up $backup_files to $dest/$archive_file"
date
echo 

#backup the files using tar
tar czf $dest/$archive_file $backup_files

#print end status message
echo 
echo 
echo "Backup finished"
date

#listing the files in $dest to check file sizes
echo "The Destination Path:"
ls -lah $dest

What causes this error and is there a simple fix?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
user3143073
  • 11
  • 1
  • 2
  • Add the following two lines to the beginning of your script: '#!/bin/bash' and 'set -xvf', (without the quotes), and run it again and post the results. – Mark J. Bobak Dec 29 '13 at 01:57
  • Possible duplicate of ['\r': command not found - .bashrc / .bash\_profile](https://stackoverflow.com/questions/11616835/r-command-not-found-bashrc-bash-profile) – Ray Oei Oct 02 '17 at 22:53

3 Answers3

4

Your blank lines aren't actually blank, because you have the wrong line ending. Try dos2unix or d2u on the file to fix the line endings.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

Try dos2unix command to convert your file in correct format.

Example: dos2unix testfile.sh

Then run again. It should work.

http://ctrlaltsolve.blogspot.in

Riddhi
  • 61
  • 1
  • 7
  • 1
    Welcome to Stack Overflow. This question has an answer from 18 months or so ago that says basically the same thing as your new answer does. While you're at liberty to answer any question, it is sensible to make sure that your answer provides something novel — doubly so when the question is old. (When it is a new question, many of the answers may be similar simply because people take a few minutes to type them up.) Adding a URL with no explanation of what's in it is not inspiring enough to warrant a new answer. I'm resisting the temptation to down-vote, but there is a temptation. – Jonathan Leffler Jun 04 '15 at 06:53
0

Notepad++ can fix this issue, no need for extra dos2unix application. I answered this here: '\r': command not found

Community
  • 1
  • 1
Inc33
  • 1,747
  • 1
  • 20
  • 26