A simple "1-liner" that I use quite a bit to get the OS version, makes it easy to create a single script that can be deployed universally.
/usr/bin/sw_vers | /usr/bin/grep 'ProductVersion:' | /usr/bin/grep -o '[0-9]*\.[0-9]*\.[0-9]*' | /usr/bin/cut -c 1-4