Article 50DED Syntax error in Bash function 'Unexpected end of file'

Syntax error in Bash function 'Unexpected end of file'

by
PasBern
from LinuxQuestions.org on (#50DED)
Hello all,

I found this Bash-function for quickly creating a backup of a file here: https://unix.stackexchange.com/quest...to-backup-file

Put it in a separate file .bash_functions and sourcing it via my .bashrc

Code:1 ##Functions
2
3 ##Create Backup of a File and append current Date and Time
4 bu () {
5 for file in "$@" do
7 local new=${file}.$(date '+%Y-%m-%d_%H.%M.%S')
8 while [[ -f $new ]]; do
9 new+="~";
10 done
11 printf "copying '%s' to '%s'\n" "$file" "$new";
12 \cp -ip "$file" "$new";
13 done
14}
15
16 ##EOF
I have removed the semi-colons in line 5 and 10 ("$@"; do and done;) as apparently this does conform with today's Bash syntax any longer. My shell was complaining about a syntax error. I took this tutorial as a guide: https://www.cyberciti.biz/faq/bash-for-loop/

Now Bash complains about an unexpected end of file. As you can see, I am not an expert regarding Bash scripting.

Code:bash: $'\r': Kommando nicht gefunden.
bash: /home/paisquy/.bash_functions: Zeile 17: Syntax Fehler: Unerwartetes Dateiende.Thanks for your hints on how I can fix this issue and tell me what is wrong with the script. I find it bizarre that the shell is complaining about line 17 when there are only 16 lines in the file.latest?d=yIl2AUoC8zA latest?i=TOPII8EDcLw:OftLimmIGa4:F7zBnMy latest?i=TOPII8EDcLw:OftLimmIGa4:V_sGLiP latest?d=qj6IDK7rITs latest?i=TOPII8EDcLw:OftLimmIGa4:gIN9vFwTOPII8EDcLw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments