I need to write a Unix Shell Script (preferably shell agnostic, but bash is ok) to verify that the system executing the .sh script has java 1.6 or greater installed and on the system path.
Thanks for the help...
Shell ScriptingJava
Last Comment
gudii9
8/22/2022 - Mon
Chris Ashcraft
This is probably what you want for the version part...
#!/bin/bash
VER=`java -version 2>&1 | grep "java version" | awk '{print $3}' | tr -d \" | awk '{split($0, array, ".")} END{print array[2]}'`
if [[ $VER ge 6 ]]; then
echo "Java version is greater than 1.6."
else
echo "Java version is lower than 1.6."
fi
http://notepad2.blogspot.com/2011/05/bash-script-to-check-java-version.html
#!/bin/bash
VER=`java -version 2>&1 | grep "java version" | awk '{print $3}' | tr -d \" | awk '{split($0, array, ".")} END{print array[2]}'`
if [[ $VER ge 6 ]]; then
echo "Java version is greater than 1.6."
else
echo "Java version is lower than 1.6."
fi