I have macOS 10.11.6. The JAVA_HOME
is set in the .bash_profile
as
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
export PATH=$JAVA_HOME/bin:$PATH
From command line, I can see it
>echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home
But, the JAVA_HOME
is empty, when I run the following script
#!/bin/sh
SHELL=/bin/sh
export SHELL
echo $JAVA_HOME
if [ -n "$JAVA_HOME" ]; then
#do something
else
echo JAVA_HOME is empty
fi
Even if I use #!/bin/bash
in my script, the JAVA_HOME
is still empty.