I'm trying to source a file with an environment variable from my bash script, but it doesn't work.
This is the content of my script (
echo "export TEST=\"test\"" > $FILE_NAME
Environment variables only flow downstream in the process tree.
When you type
testScript to a bash process, it creates a child process and execs
/bin/bash or whatever is set by
Any environment variables set there remain only with the child process. Export causes the variables to be copied to additional grandchildren (children of that child) that might be spawned from that child.
Nothing can copy back to a parent. You need to use source instead of running the file. See Jonathan's answer.
You could try editing the files
~/.login to set enviornment variables you need frequently.
See also http://superuser.com/q/153371 and http://superuser.com/questions/18988/difference-between-a-b-and-export-a-b-in-bash for more explanation of