You can use these variables in script logic to run different commands based on the version of macOS.
On the macOS Version
Never would have spotted those scripts. Jawa 3, 8 24 EdmundsZ EdmundsZ 89 1 3. If all you care about is the major version Joe Block Joe Block 3. Sign up or log in Sign up using Google. Thanks to the participants of this Slack discussion.
Finding the Command Line
Aside from the numerical version number or product version, macOS also has a build number, which follows a different schema. Mac OS X Currently, macOS High Sierra Then follows a single capital letter, with A being the first release of a version i.
Finally the last number is the build number. The build number usually incremented during Apple internal development.
You can see the build number increasing during beta releases. However, sometimes Apple will release hardware specific versions of macOS which usually have four digit build numbers usually starting with a 2.
How to Display the macOS/OS X Version From the Command Line - The Mac Observer
Sometimes there might be an a appended to the build number. This means that there was an update to the installer, but not the code inside the installer. This frequently but not exclusively happens during the beta phase. You can programmatically compare if you split the string right. Because of this it can also be useful to parse the build number out of the build version.
Since the first two parts of the build version are directly mapped to the numerical version, we are only interested in the number:. You can get all this code in a sample script I posted on gist. Your email address will not be published. Notify me of follow-up comments by email.
Notify me of new posts by email. This site uses Akismet to reduce spam.
Learn how your comment data is processed. Skip to content. You can test for a specific version with string comparison: You can also split the version string into a bash array: Once you have split out the parts of the version string, you can then use them for numerical comparisons: In an installation script postinstall or preinstall you can get the target system with: