Reputation: 6462
I need to run make with one parameters set if it is running under Capitan and with other parameters in Sierra. In other words: I run in command line:
sw_version ProductName: Mac OS X ProductVersion: 10.13.6
How I can get the value of ProductVersion to the variable and check it if current OS version <10.13 then else
Upvotes: 2
Views: 2768
Reputation: 396
The below command works on latest versions of macOS:
os_ver=${$(sw_vers -productVersion)}
if [[ $os_ver -gt 10.13 ]]; then
echo "$os_ver is above 10.13"
else
echo "$os_ver is below 10.13"
fi
Upvotes: 2
Reputation: 4574
try the sw_vers
command. See examples here :
https://www.cyberciti.biz/faq/mac-osx-find-tell-operating-system-version-from-bash-prompt/
to get product version :
sw_vers | grep ProductVersion | cut -d':' -f2
to compare the parsed value :
base_ver=10.13
ver=$(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ')
if [ $(echo -e $base_ver"\n"$ver | sort -V | tail -1) == "$base_ver" ]
then
echo "older"
else
echo "newer"
fi
Upvotes: 3