sw_vers

This simple built-in command provides the version and build number of Mac OS X being used. In 10.2.x, there is only one form of the command, which also works in 10.3 or greater:

% sw_vers
ProductName: Mac OS X Server
ProductVersion: 10.4.9
BuildVersion: 8P135

In the Panther (Mac OS 10.3.x) and the Tiger (10.4.x) versions, you may optionally specify a parameter to get a single field's data. One oddity to watch for however is that although sw_vers has field labels that begin with an uppercase character, the command options always expects a lowercase character as the first letter.

SW_VERS(1)  BSD General Commands Manual  SW_VERS(1)

NAME
 sw_vers - print Mac OS X operating system version information

SYNOPSIS
 sw_vers
 sw_vers -productName
 sw_vers -productVersion
 sw_vers -buildVersion

DESCRIPTION
 sw_vers prints version information about the Mac OS X or Mac OS X Server
 operating system running on the local machine.

 When executed with no options sw_vers prints a short list of version
 properties:

 % sw_vers
 ProductName: Mac OS X
 ProductVersion: 10.3
 BuildVersion: 7A100

The ProductName property provides the name of the operating system
release (typically either "Mac OS X" or "Mac OS X Server"). The
ProductVersion property defines the version of the operating system
release (for example, "10.2.4" or "10.3"). The BuildVersion property
provides the specific revision of the operating system as generated by
the Mac OS X build system.

OPTIONS
The output of sw_vers can be refined by the following options.

-productName Print just the value of the ProductName property.

-productVersion Print just the value of the ProductVersion property.

-buildVersion Print just the value of the BuildVersion property.

EXAMPLES
% sw_vers -productName
Mac OS X

% sw_vers -productVersion
10.3

% sw_vers -buildVersion
7A100

FILES
/System/Library/CoreServices/SystemVersion.plist
/System/Library/CoreServices/ServerVersion.plist

Mac OS X March 10, 2003 Mac OS X

The Gestalt Alternative

AppleScript, Python, and Perl provide access to the system's Gestalt values, which provides access to many useful system values. One caveat: many of the older selectors are no longer provided (or relevant) since the switch to OS X. The 'sysv', 'sys1', 'sys2', and 'sys3' selectors still work however, and can be used to get the all or part of the OS version number.