I have the following:
versionNumber=$(sw_vers -productVersion) # Finds version number
versionShort=${versionNumber:0:4} # Cut string to 1 decimal place for calculation
which works when versions are like this:
10.9.2
10.9.5
but it will not match
10.10.3
as it will return only
10.1
but I want the versionShort to be set to
10.10
I am wanting to match the major version, the first dot and the minor version as above.
Regexpless solution - cut off last dot and whatever follows it:
versionShort=${versionNumber%.*}