Avatar of cgray1223
cgray1223
 asked on

Unix Shell Script To Verify Java Version

Hello,

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

Avatar of undefined
Last Comment
gudii9

8/22/2022 - Mon
Chris Ashcraft

This is probably what you want for the version part...

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
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Juan Carlos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
gudii9

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy