You mustcan run the assignment and echo test srciptscript in the same shell.
root@ijaz-HP-EliteBook-8560p:~# export foo=bar
root@ijaz-HP-EliteBook-8560p:~# cat test.sh
#!/bin/bash
echo "$foo"
root@ijaz-HP-EliteBook-8560p:~# . /test.sh
bar
this is just one way of doing it.