UPDATE (10/8/08): The following one-liner will work on ppc or intel boxes and will return 1 if the computer is 64-bit capable or 0 if it is not. UPDATE 2 (12/11/08): Reader Ted suggested suppressing stderr for cleaner output. I amended the code below to include his suggestion.
sysctl hw.optional 2> /dev/null | awk -F': ' '/64/ {print $2}'
The arch tool is an easy way to test whether a Mac’s processor is intel or ppc, but it does not draw a distinction between the different types of intel processors. It will return i386 whether it’s a Core Duo, Core 2 Duo, or Xeon. We can use the fact that the Core Duo is only intel processor found in Macs incapable of running 64-bit code to write a script that extend arch to test for 64-bit capability.
#!/bin/bash
proc=$(/usr/sbin/system_profiler SPHardwareDataType | \
/usr/bin/awk -F': ' '/Processor Name:/ {print $2}')
if [ "$(/usr/bin/arch)" == "i386" ]; then
if [ "$proc" != "Intel Core Duo" ]; then
/bin/echo $(/usr/bin/arch)-64
else
/bin/echo $(/usr/bin/arch)-32
fi
else
/bin/echo $(/usr/bin/arch)
fi
This script will return i386-32 for intel processors limited to 32 bits, i386-64 for 64-bit capable intel processors, and ppc for non-intel processors.
I’ve called this script archbits and made it downloadable here.
Follow me on twitter