I wrote a script named java_home.sh
with the following content
export JAVA_HOME=/path/to/java/home
I ran ./java_home.sh
on the command line, and then I did echo $JAVA_HOME
- the script did not work, JAVA_HOME
has not been set.
But copying the content of the script and typing on the terminal
export JAVA_HOME=/path/to/java/home
does the trick - the environment variable is added.
I'm confused - how is running the script directly different from copying out its content and run it myself? They produce different results.
P.S. I wrote the script with the intention of putting it under /etc/profile.d
so that it can set the environment variable for all users when the system starts up, so it bothers me that the script is not working.