Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
zsh script to compare macOS Versions - see for full explanation
#!/bin/zsh -f
# Purpose: Check to see if we are running on Big Sur
# From: Timothy J. Luoma
# Mail: luomat at gmail dot com
# Date: 2020-07-10
# this will check to make sure `sw_vers` exists
# if it does not, this is probably not macOS
if ((! $+commands[sw_vers] ))
echo "$NAME: 'sw_vers' is required but not found in $PATH" >>/dev/stderr
exit 2
## First we get the value for this Mac and save it to `$ACTUAL`
ACTUAL=$(sw_vers -productVersion)
## load 'is-at-least' so we can use it
autoload is-at-least
## "Is the version of macOS that we are using _at least_ 10.16?"
is-at-least "10.16" "$ACTUAL"
## EXIT will be '0' if ACTUAL is at least 10.16
## EXIT will be '1' if ACTUAL is _less than_ 10.16
if [[ "$EXIT" == "0" ]]
# This is Big Sur (or later)
echo "YES"
elif [[ "$EXIT" == "1" ]]
# This is BEFORE Big Sur
echo "NO"
# we should never get here
echo "This should not have happened. EXIT = $EXIT"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.