As a normal user I can get the version of OS X with the command
$ defaults read loginwindow SystemVersionStampAsString
However, if I run the command as root it fails:
$ sudo defaults read loginwindow SystemVersionStampAsString
2012-08-22 18:51:06.941 defaults[427:1707]
The domain/default pair of (loginwindow, SystemVersionStampAsString) does not exist
Any clues?
There’s a command line tool called ‘sw_vers’:
It should print out the version information; for example: