Fetch the value from Here Document

I have code like

var="1"
echo << EOF
export `var="2"`
EOF
echo $var

The value of var is printed here is 1 but it should be 2
Any error there?

---------- Post updated at 11:44 AM ---------- Previous update was at 10:33 AM ----------

Also tried

var="1"
echo var << EOF
echo "2"
EOF
echo $var

That isn't the way echo works and that isn't the way here-documents work.
The echo utility doesn't read standard input, so nothing being done in the here document will be echo'ed by echo.

A here-document operates in the shell execution environment of the command that will be run; not in the current shell execution environment. So, anything you execute in the here-document may affect echo's environment, but it won't be visible in the environment of the shell that ran echo.

The purpose of a here-document is to create text that will be able to be read from the file descriptor specified (fd 0 by default) by the command line that contains the here-document.

If you put the text var=value in a here-document, the shell doesn't assign value to var; it just makes the stirng "var=value" available to be read from standard input of the command. You can see this if you use cat instead of echo:

cat <<EOF
var=value
variables are expanded (\$HOME is $HOME)
command substitutions are performed 2+2 is $(echo 2 + 2|bc)
but variables that affect the environment of the shell calling cat cannot be set
EOF

which produces

var=value
variables are expanded ($HOME is /Users/dwc)
command substitutions are performed 2+2 is 4
but variables that affect the environment of the shell calling cat cannot be set