os-get-version-on-mac

135 阅读1分钟

os get version on mac so easily on 1-3 lines

  • os get version from SystemVersion.plist
  • os get version from sw_vers

howto

# get os version from SystemVersion.plist
shf=/usr/libexec/PlistBuddy;shf_data=/System/Library/CoreServices/SystemVersion.plist;
[ -e "$shf" ] && [ -e "$shf_data" ] && ver=`"$shf" -c "Print:ProductName" -c "Print:ProductVersion" -c "Print:ProductBuildVersion" "$shf_data"`;

# get os version from sw_vers
[ "$ver"_ == "_" ] && ver=`sw_vers | awk	-F':' '{print $2}'|awk '{$1=$1;print}'`;

[ "$ver" ] && echo $ver | sed -n "2p"

todo

  • save and set more custom about these code to your gitee or github or other git repo.
  • use in 1 line .

refers

identify-the-macos-version-from-the-command-line

test on my mac os

  • macos 10.15.7