Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, I'm kinda new to using BASH and I would like to know how I can compare two version strings to see if they are Greater than, Less than or ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    1

    BASH - Version string compare


    Hello,
    I'm kinda new to using BASH and I would like to know how I can compare two version strings to see if they are Greater than, Less than or equal.

    For example i have these two versions strings

    a=10.1.0.53
    b=10.1.2.8

    Does anyone have an example or sample script on comparing these two version strings?

    Thanks,
    tom

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    477
    if the version strings are in a file "file"

    10.1.0.53
    10.1.2.8

    then

    sort -nr <file |head -1

    will give you the bigger, but

    sort -n <file |head -1

    the smaller
    the sun is new every day (heraclitus)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •