[Bash]检查java版本信息
#!/bin/bash #set -x if 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}') #it will give you 16 for java like 1.6.0_13 and 15 for version like 1.5.0_17. version=$(java -version 2>&1 | sed 's/java version "(.*).(.*)..*"/12/; 1q') echo version "$version" [ "$version" -ge 15 ] && echo "ok, java is 1.5 or newer" || echo "it's too old..." fi