如何检查Java是否可用(在PATH或通过JAVA_HOME)从bash脚本,并确保版本至少为1.5?
也许像:
原文链接:https://www.f2er.com/bash/389992.htmlif type -p java; then echo found java executable in PATH _java=java elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then echo found java executable in JAVA_HOME _java="$JAVA_HOME/bin/java" else echo "no java" fi if [[ "$_java" ]]; then version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}') echo version "$version" if [[ "$version" > "1.5" ]]; then echo version is more than 1.5 else echo version is less than 1.5 fi fi