Apple - Output of "${OSTYPE:6}" on old releases of Mac OS X

That sounds very much like it's returning the Darwin version.

Your theory works well from 10.15 Mojave [18] back to 10.2 Jaguar [6] but fails before that, as Darwin was 1.x.x at that point.

There's a full list at Wikipedia - macOS


On a machine running 10.13 High Sierra, echo ${OSTYPE:6} returns 17...

Here's an old PowerMac G5 running OS X 10.5 circa 2009:

$ bash --version
GNU bash, version 3.2.17(1)-release (powerpc-apple-darwin9.0)

$ sh --version
GNU bash, version 3.2.17(1)-release (powerpc-apple-darwin9.0)

$ echo ${OSTYPE:6}
9.0

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.5.8
BuildVersion:   9L31a

$ system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: Mac OS X 10.5.8 (9L31a)
      Kernel Version: Darwin 9.8.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: PowerMac
      User Name: Jeffrey (jwalton)
      Time since boot: 66 days 3:46

I've never used if [[ ${OSTYPE:6} -ge 14 ]]; then DoThing; fi. However, I've used similar to this in shell scripts and Makefiles:

IS_OLD_DARWIN=$(system_profiler SPSoftwareDataType 2>/dev/null | grep -i -c -E "OS X 10\.[0-5]")
if [[ "$IS_OLD_DARWIN" -ne 0 ]]; then DoThing; fi

I can provide remote SSH access to the PowerMac. I use it for testing open source libraries, like Crypto++ and OpenSSL. Email me at noloader, gmail account if you want access.

As far as I know, the oldest version of Bash you can get your hands on for testing is Bash 2.x circa 2004. Download Fedora 1 from /pub/archive/fedora/linux/core.


I don't have a 10.0 machine to test on, but on 10.3 and 10.5 machines, echo ${OSTYPE:6} returns a blank line ($OSTYPE on both is darwin); on 10.6, it returns 10.0.

(Incidentally, your shell script would need to explicitly invoke bash. The default shell on very old versions of OSX is tcsh, which doesn't understand the ${OSTYPE:6} syntax.)

Tags:

Macos