views:

218

answers:

3

Hi All, I am usig Fedora 10. if I write java -version in terminal, it gives me java version. I want to write a shell script file to check whether the java version is greater than 1.5. The main problem is that I donot know how to assign the value of java -version command as to a variable of shell script.

How to create shell script file for that.

Thanks Sunil KUmar Sahoo

+2  A: 

Use backticks:

JAVA_VERSION=`java-version`
innaM
can i confirm you did get a result in JAVA_VERSION variable?
ghostdog74
Well? Can you confirm it?
innaM
+3  A: 

As answered above, you can use backticks or (if your keyboard doesn't have them) use the following format:

JAVA_VERSION=$(command)

lorenzog
+1  A: 

you should direct stderr to stdout

$ var=$(java -version 2>&1)
$ set -- $var
$ echo $3
"1.6.0_0"
$ echo ${3//[._\"]/}
1600

Now you can compare $ver to see if its greater than 1500.

ghostdog74