I am trying to do an action in a IF ELSE statement in Bash, but receive an error like this one:
Syntax error: end of file unexpected (expecting "fi")
Now I am quite new to this, so probably the solution to my problem should not be that difficult :)
if [ "$DAYNAME" = 'Sunday' ]; then
echo 'The backup will be uploaded'
ftp -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
put $filetoday
delete ${filethreeweeksago}
quit
EOF
fi
Of course the vars are already filled.
I think it has to do with the EOF notation, because when i remove them, the problem disapears. Unfortunatly I don't know how to use the code without the EOF notation.
Can anyone tell me why this error is comming up?
This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended. Similarly, in bash, the EOF operator is used to specify the end of the file.
Save this answer. Show activity on this post. There is no way to echo out an EOF. An EOF can only be generated either by reaching the end of a file or by invoking the keypress bound to the eof terminal setting ( Ctrl D by default) when the file being read is bound to the terminal.
the “end-of-file” (EOF) key combination can be used to quickly log out of any terminal. CTRL-D is also used in programs such as “at” to signal that you have finished typing your commands (the EOF command). CTRL-Z. key combination is used to stop a process. It can be used to put something in the background temporarily.
Drop the blanks and it should work:
EOF
^^^^
add a dash to EOF if you want to keep the tabs: from:
ftp -n $HOST <<EOF
to:
ftp -n $HOST <<-EOF
https://github.com/koalaman/shellcheck/wiki/SC1039
The here document delimiter will not be recognized if it is indented.
You can fix it in one of two ways:
1.Simply remove the indentation, even though this may break formatting.
2.Use <<- instead of <<, and indent the script with tabs only (spaces will not be recognized).
Removing the indentation is preferred, since the script won't suddenly break if it's reformatted, copy-pasted, or saved with a different editor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With