bash EOF in if statement

13,955

Solution 1

Drop the blanks and it should work:

    EOF
^^^^

Solution 2

add a dash to EOF if you want to keep the tabs: from:

ftp -n $HOST <<EOF

to:

ftp -n $HOST <<-EOF

Solution 3

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.

Share:
13,955
Arthur
Author by

Arthur

I'm trying to learn something about php, especially Zend Framework. Since i'm a starter please don't be hard on me :)

Updated on July 26, 2022

Comments

  • Arthur
    Arthur almost 2 years

    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?