You can get the OS version with sw_vers -productVersion
-- that'll print something like "10.8.5". However, this may not be straightforward to compare. When Apple releases the successor to Mavericks, it'll probably be numbered 10.10, and "10.10" is textually less than "10.6.8" (because "1" < "6"). You could parse the version string into its components and compare elements numerically (see this previous question), but that's rather messy.
It's probably easier to check the Darwin version with uname -r
-- that'll print something like "12.5.0", which actually does correspond to the OS version, but in a nontrivial way:
- Darwin 10.x = OS X 10.6.x (and iOS 4)
- Darwin 11.x = OS X 10.7.approxamatelyx (and iOS 5)
- Darwin 12.x = OS X 10.8.approxamatelyx
- Darwin 13.x = OS X 10.9.x (and iOS 6)
- Darwin 14.x = iOS 7
... but that's actually easier for major version comparison, since you can just look at the first number to get the major version:
darwin_version=$(uname -r)
if (( ${darwin_version%%.*} < 11 )); then # %%.* removes the first period and everything following that
# do OS X 10.6 stuff
else
# do OS X 10.7-10.9 stuff
fi