If you ever need to detect number of CPU cores, number of CPU’s installed in your Mac with a shell script, this is a very good method for it :
Number of Cores :
/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | awk '/Total Number Of Cores/ {print $5};'
Number Of Processors
/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | awk '/Number Of Processors/ {print $4};'
Also try, system_profiler -detailLevel full for many, many other hardware/software information.
p.s. I used this core detection in my x264, xvid encoding shell script to autodetect number of threads I would use.
4 cores = 4 threads on my XEON Mac Pro.
2 cores = 2 threads on my MacBook Pro (Core 2 Duo)