我编写了一个shell脚本来检查Java是否安装在系统中。
现在我想要这样的逻辑:
这是我的代码:
(update-java-alternatives -l | \
grep oracle | \
awk '{system(""$3"/bin/java -version 2>&1 | \
grep \"java version\"")}') | \
awk -F\" '{print $1}''{print $2}'
read -p "Continue (y/n)?" choice
case "$choice" in
y|Y ) echo "$(tput setaf 1) $(tput setab 7)Adding PPA$(tput sgr 0)"
sudo add-apt-repository ppa:webupd8team/java
echo "$(tput setaf 1)$(tput setab 7)updating repositories$(tput sgr 0)"
sudo apt-get update
sudo apt-get install oracle-java8-installer
echo "$(tput setaf 1)$(tput setab 7)instaling software-properties-common$(tput sgr 0)"
sudo apt-get install software-properties-common ;;
n|N ) echo "no" ;;
* ) echo "invalid" ;;
esac