Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to update a script compilation from time to time but I haven't any idea how to start a version check script in bash.

I've got a version file with 3 vars: version=0, subversion=0 and subsubversion=1 and I've got a web server that serves the updates with install routines as bash scripts. In a directory called updates:


and a directory called current where the current version is stored.


Now I'd like to have a script that takes $version, $subversion and $subsubversion and determines witch update to download and execute. After this part has finished the update script should increment a var so that it downloads the next update if it is available. Let's call it nextversion.

I stuck with incrementing the three vars and thenextversion variable in the update script.

What could I do to increment the tree vars and a fourth var to the next higher level. How do I handle it if I go from 0.0.9 to 0.1.0 or even from 0.9.9 to 1.0.0 and so on. Without producing a lot of if-else-elif statements. I'm sadly not good in figuring out loops.

share|improve this question
Version numbers are just numbers. So after 0.9.0 you of course can also have a 0.10.0. But if you want to make things easy, just use something like a revision number which you simply count up. So just stick to 1, 2, 3, 4, and so on. – Shi Aug 10 '13 at 20:15
This sounds like a really inefficient way to do the updating -- if a particular script has been updated 10 times between the version on the client and the latest one, should it really download each of the 9 intermediate versions in sequence? – Gordon Davisson Aug 12 '13 at 3:47
Basically it should be able to update the system regardless witch version is installed. I haven't any idea how to use git for this. If I had I would use it instead of bash. – Josh Aug 13 '13 at 6:47

This breaks after 9.9.9



  if [ "$subsubversion" -lt 9 ]; then
  elif [ "$subsubversion" = 9 ] && [ "$subversion" -lt 9 ]; then
    subsubversion="0"; subversion=$((subversion+1));
  elif [ "$subsubversion" = 9 ] && [ "$subversion" = 9 ] && [ "$version" -lt 9 ]; then
    subsubversion="0"; subversion="0"; version=$((version+1));
    echo "overflow"

  echo "${version}.${subversion}.${subsubversion}";


Perhaps you'd rather use git instead?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.