0

I'm trying to get BASH to return a result where if a particular software version contains two decimals values, that it's greater than one?

Example, I would like the result to confirm that 1.12 is greater than 1.8:

1.12 > 1.8

Since .8 > .1#, I'm not getting the results I want. I've tried various ways such as:

version='1.11'
if [[ $version} > 1.8 ]]'; then
...

I've also tried to see if I could get 'bc' calculator to return a different result, but unfortunately it also does not provide the result that I'm after:

echo 1.11'>'1.8 |bc
0
echo 1.9'>'1.8 |bc
1

Any thoughts on how this can be achieved?

hobbes
  • 467
  • 1
  • 7
  • 22
  • I should mention that this *is* for version control comparisons. So the whole integer value also needs to be accounted for. – hobbes Apr 05 '18 at 05:47

1 Answers1

2

suggestion:

version1='1.11'
version2='2.8'

maxWidth=3

while [[ ${#version1} -le $maxWidth ]]; do
    version1="${version1}0"
done
while [[ ${#version2} -le $maxWidth ]]; do
    version2="${version2}0"
done

[[ ${version2/\.} -gt ${version1/\.} ]] && echo "v2>v1" || echo "v2<=v1" 

fix for antak's remark

kyodev
  • 573
  • 2
  • 14