我试图编写一个在JDK和JRE以及x86和x64架构之间切换的脚本。
但是,当我执行:echo $PATH
或echo $JAVA_HOME
或echo $JRE_HOME
时,不会打印任何内容!路径打印但没有添加java。
我的脚本如下,它会在最后导出路径。
#!/bin/bash
#sudo apt-get install oracle-java8-installer
x64_JDK_PATH="/opt/java/jdk1.7.0_51"
x64_JRE_PATH="$x64_JDK_PATH/jre"
x86_JDK_PATH="/opt/java/jdk1.7.0_51_x86"
x86_JRE_PATH="$x86_JDK_PATH/jre"
xJAVA_PATH=""
echo
echo -e "What would you like to switch to?"
echo -e " 1. JDK (Java Development Kit)\n"
echo -e " 2. JRE (Java Runtime Environment)\n"
echo -e "Choice: \c"
read ENV_ANSWER
echo
case $ENV_ANSWER in
1)
echo -e "Switching to the JDK (Java Development Kit)\n"
;;
2)
echo -e "Switching to the JRE (Java Runtime Environment)\n"
;;
*)
echo -e "Invalid option.\n"
echo -e "Script terminating.\n"
exit
;;
esac
echo -e "What version would you like to switch to? (x32\\\x64): \c"
read ARCH_ANSWER
if [ $ARCH_ANSWER != "x32" ] && [ $ARCH_ANSWER != "x64" ]
then
echo -e "Invalid version. Versions are 'x32' and 'x64'."
echo -e "Script terminating.\n"
exit
fi
echo "Switching to the $ARCH_ANSWER version."
echo
if [ $ARCH_ANSWER = "x32" ] && [ $ENV_ANSWER = 1 ]
then
xJAVA_PATH=$x86_JDK_PATH
elif [ $ARCH_ANSWER = "x32" ]
then
xJAVA_PATH=$x86_JRE_PATH
fi
if [ $ARCH_ANSWER = "x64" ] && [ $ENV_ANSWER = 1 ]
then
xJAVA_PATH=$x64_JDK_PATH
elif [ $ARCH_ANSWER = "x64" ]
then
xJAVA_PATH=$x64_JRE_PATH
fi
sudo update-alternatives --install "/usr/bin/java" "java" "$xJAVA_PATH/bin/java" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "$xJAVA_PATH/bin/javaws" 1
if [ $ENV_ANSWER = 1 ]
then
sudo update-alternatives --install "/usr/bin/javac" "javac" "$xJAVA_PATH/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javadoc" "javadoc" "$xJAVA_PATH/bin/javadoc" 1
fi
sudo update-alternatives --set java "$xJAVA_PATH/bin/java"
echo
echo -e "Would you like to update your Mozilla Plugins as well? (y\\\n): \c"
read PLUGINS_ANSWER
if [ $PLUGINS_ANSWER = "Y" ] || [ $PLUGINS_ANSWER = "y" ]
then
rm "$HOME/.mozilla/plugins/libnpjp2.so"
mkdir -p "$HOME/.mozilla/plugins"
ln -s "$xJAVA_PATH/jre/lib/amd64/libnpjp2.so" "$HOME/.mozilla/plugins/"
echo -e "Mozilla Plugins updated.\n"
else
echo -e "Mozilla Plugins left untouched.\n"
fi
JAVA_HOME=$xJAVA_PATH
JRE_HOME=$xJAVA_PATH
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
java -version
echo
任何想法都有什么问题吗? java -version
打印得很好。一切都有效,除了出口路径..