macosterminal

How to return app version in terminal on osx


I am needing to use app version in a .sh script on Mac osX 10.10 so that I can do a compare to another number so I can force an update or not.

So far I have this (I am using Firefox.app as an example)

FirefoxmdlsVersion= mdls -name kMDItemVersion /Applications/Firefox.app;
echo $FirefoxmdlsVersion

This returns kMDItemVersion = "34.0"which is a step in the right direction but I need just the number so that I can do my compare example 340

Here is what I have attempted to do with a new variable but I dont get an error or output at all

FFV2=${FirefoxmdlsVersion//'kMDItemVersion ='}
FFV3=${FirefoxmdlsVersion:18:4}

I maybe going in the wrong direction here, but Ive looked a post and havent made any progress. Can anyone help me?


Solution

  • You could use tr as well:

    FirefoxmdlsVersion= mdls -name kMDItemVersion /Applications/Firefox.app | tr -d ".";
    

    Which produces 3405 (From Firefox 34.0.5)