How to retrieve and store java version in a bash variable
Sometimes, checking installed java version is needed in a shell script, and it is useful to easily retrieve and store it in a variable.
Here is a tip to do this in one line :
#!/bin/sh
JAVA_VERSION=`echo "$(java -version 2>&1)" | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
Written by eviweb
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#