-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckForJava.sh
More file actions
34 lines (31 loc) · 1.13 KB
/
Copy pathcheckForJava.sh
File metadata and controls
34 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
## Check to see if the required version of Java is available on the
## command line PATH
##
## Adapted from
## https://stackoverflow.com/questions/7334754/correct-way-to-check-java-version-from-bash-script/7335120
function checkForJava() {
if type -p java; then
echo "Found java executable in execution 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 "Could not find java in your environment"
return 1
fi
if [[ "$_java" ]]; then
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
minimumVersion="11"
echo You are running Java version "$version"
if [[ "$version" > "$minimumVersion" ]]; then
echo This version of Java is sufficient for this course
return 0
else
echo "** This version of Java is sufficient NOT for this course."
echo "** Please install at least version ${minimumVersion} of the JDK."
return 1
fi
fi
}