I am trying to do a IF..ELSE inside a heredoc. The heredoc is necessary because the set of commands need to be executed as a different user. 
Unfortunately, the IF statement doesn't work as expected, and always jumps to the ELSE clause. When I remove the IF block from the heredoc and place it outside it works as expected. 
It is probably a simple thing I'm missing, but I have no idea what.
rem=0
function1 () {
    su - user1 <<'DONE'
        if [[ "$rem" -eq 0 ]];
        then
            echo rem is even
        else
            echo rem is odd
        fi
DONE
}
function1
It echoes rem is odd.
 
    