Posts RSS Comments RSS 48 Posts and 155 Comments till now

Get the system version using Terminal

There is a nice utility available from the command line that allows you get some basic system information quickly. All of this information is available in other places but there are times when it’s easier to get it at the command line.

Open up Terminal and type “sw_vers” (no quotes) and hit return. The results you’ll get look like this:


ProductName: Mac OS X
ProductVersion: 10.4.9
BuildVersion: 8P135

You can use different variations such as “sw_vers -productVersion” to get just that information. On the same machine in the first example that would return:


10.4.9

I recently had a need to get this information at the command line for an installer I was building. I only needed to know the first part of the product version (10.3, 10.4, etc.) so I put together a short shell script to grab that information for me.


#!/bin/bash

sysver=`sw_vers -productVersion | cut -c 1-4`
echo $sysver

if [ $sysver = 10.4 ]; then
echo "This is a Tiger System"
elif [ $sysver = 10.3 ]; then
echo "This is a Panther System"
else
echo "This system is too old"
fi

This script was just a “proof of concept” on for me. Once I knew it worked I could control what things happened depending on if the machine was running 10.4, 10.3 or an older version. Just substitute the “echo” statements for what should happen. If you want to try this out paste the script into a plain text document and save it with a “.sh” extension. Go into Terminal and make it executable with chmod.

Comments are closed.