0

I am trying to write this shell script to verify the version of make which is installed on the linux, but unable to get it working. It will be great if someone can point me what I am missing here.

OUTPUT="$(make --version | head -1)"
echo "${OUTPUT}" | grep -o '[0-9]*[\.][0-9]*'

OP="$(echo \"${OUTPUT}\" | grep -o '[0-9]*[\.][0-9]*')" 
echo "${OP}"

if [ $OP -ge 3.82 ]; then
  echo "make version is greater than or equal to 3.82"
else:
  echo "make version is not greater than or equal to 3.82"
  exit 1
fi

2 Answers2

1

You can only use test (aka [) to compare strings and integers, not versions like that. Here's two questions that show you ways to compare versions:

0

don't use the char ":" after the key-word else:

if [ $OP -ge 3.82 ]; then
  echo "make version is greater than or equal to 3.82"
else
  echo "make version is not greater than or equal to 3.82"
  exit 1
fi
Grégory Roche
  • 162
  • 2
  • 9