Find the answer to your Linux question:
Results 1 to 4 of 4
I am interested in testing version numbers within bash script. I have googled for good examples but have not seen what I am looking for.. if a product were to ...
  1. #1
    Just Joined!
    Join Date
    Sep 2003
    Location
    hants
    Posts
    2

    bash script testing version numbers

    I am interested in testing version numbers within bash script.

    I have googled for good examples but have not seen what I am looking for..

    if a product were to be be on version
    3.33.10

    How to check that that the patch was only 3.33.11 or version 3.34.0

    for instance it could be that the next patch is a patch and it will only upgrade the version number by one or it is a release and will move totally away.

    3.33.11 would be valid
    3.33.12+ would fail
    3.34.0 would be valid
    but 3.34.1 would fail
    or 3.34.01 would fail


    If I have not explained full please do ask away...

    Thanks for reading

    hdaz

  2. #2
    Linux Newbie
    Join Date
    Sep 2004
    Location
    UK
    Posts
    160
    Break the new version and old version numbers to major, minor and revision numbers

    eg.
    Code:
    OLD_VERSION=2.3.11
    NEW_VERSION=2.3.12
    
    c_major c_minor c_rev << EOF
    `echo ${OLD_VERSION} | tr "." " "`
    EOF
    
    read n_major n_minor n_rev << EOF
    `echo ${NEW_VERSION} | tr "." " "`
    EOF
    Then code the logic to compare the numbers.
    In a world without walls and fences, who needs Windows and Gates?

  3. #3
    Just Joined!
    Join Date
    Sep 2003
    Location
    hants
    Posts
    2
    blinky,


    Many thanks for the fast reply... my memory is failing me I have seen this example before someplace...

    Thanks

  4. #4
    Linux Newbie
    Join Date
    Sep 2004
    Location
    UK
    Posts
    160
    Should be a read at the start of line "c_major c_minor c_rev << EOF"

    eg.
    Code:
    OLD_VERSION=2.3.11
    NEW_VERSION=2.3.12
    
    read c_major c_minor c_rev << EOF
    `echo ${OLD_VERSION} | tr "." " "`
    EOF
    
    read n_major n_minor n_rev << EOF
    `echo ${NEW_VERSION} | tr "." " "`
    EOF
    In a world without walls and fences, who needs Windows and Gates?

Posting Permissions

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