When you run a script, it runs in a subshell. Variables are only valid within the context of that subshell. Set them in your .bashrc
or .profile
and read up on variables and subshells. The export
statement works down hierachy (current shell and all it's subshells) not up as in your example.
Alternatively (if you really want the script to effect the enviroment of your current shell) run it as:
. ./script.sh
That causes it to run in your current shell but will not pass variables up the hierarchy either.