#export java home to current shell environment
Executing a file “./script.sh”:
Linux take script.sh as a executable binary file.
When the file is executed, a new sub-shell will be created and the script is run in the new sub-shell. When it finishes, the sub-shell exit automatically. So executing this file does not make any changes of the current shell.
$ echo $JAVA_HOME
So in this case, JAVA_HOME is still not set in current shell.
Sourcing a file “source ./script.sh” “. ./script.sh”
Sourcing will run the commands in the current shell process. The lines of code were executed as if they were printed at the command line. So it is import to source a file to make the changes of the file applicable to current shell. Usually, the alias or profile files are often sourced since they contain stuffs like setting of environment variables , aliases definition, etc.
bash-3.2$ source setEnv.sh
bash-3.2$ echo $JAVA_HOME