Parsing the string in bash script

sduser1
sduser1 used Ask the Experts™
on
VERSION="Google Chrome 76.0.3809.100" . (Need to split and get only the version (76.0.3809.100)
#echo $VERSION

IFS=' ' read -a VERSION <<< "$VERSION"
    if "${VERSION[@]}"= "76.0.3809.100"
then
        echo "${VERSION[@]}"
fi

It is not working. Please help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
VERSION="Google Chrome 76.0.3809.100" #. (Need to split and get only the version (76.0.3809.100)

# 3 different ways to do it ....
VER=$(echo $VERSION | sed 's/Google Chrome //')
echo SED-version=$VER
VER=$(echo $VERSION | awk '{ print $3; }')
echo AWK-version=$VER
VER=$(echo $VERSION | cut -d " " -f 3 )
echo CUT-version=$VER

VERSION=$VER

if [ "$VERSION" == "76.0.3809.100" ]
then
        echo "${VERSION}"
fi

Open in new window

Fractional CTO
Distinguished Expert 2018
Commented:
To reference the version number, you'd say...

imac> FS=' ' read -a VERSION <<< "Google Chrome 76.0.3809.100"

imac> echo ${VERSION[2]}
76.0.3809.100

Open in new window

Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
Personally I would do it with straight Bash string manipulation.

Try this:
version="Google Chrome 76.0.3809.100"
echo "Version: ${version##* }"

Open in new window

Author

Commented:
Thanks to 3 of you. All of them worked.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
You're welcome!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial