how to import linux command in shell script file as the value of a variable ?

I am using 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 ?


Use backticks:


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


you should direct stderr to stdout

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

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

All the above Answer will work for you. below are the common example which you can use to get the value of variable:

JAVA_VERSION=`java-version` or JAVA_VERSION="java-version" or JAVA_VERSION=$(command)

The way is to set the value of variable is many. You can use your easiest way to fulfill your requirement. Like I'm using

var=$(awk -F'"' '/^variable=/ {print $2}' )
echo $var

Need Your Help

Python: AttributeError: type object 'Ui_Form' has no attribute 'comboBox'


I have two modules and The fill_combobox is for a default values in the combobox. There is still a problem with communication between modules.