#!/bin/bash
#
# Returns cpu count as defined by /proc/cpuinfo.
# Optional argument will allow you to modify the
# return value using "+N" or "-N" (e.g. cpucount +1)

# get cpu count
count=$(cat /proc/cpuinfo | ack "^processor\s+:" | wc -l)

# modify count with optional arg
if [ $# -gt 0 ] && [ -n "$1" ]; then
	count=$(( $count $1 ))
fi

# clearly there's at least 1 cpu
if [ $count -lt 1 ]; then
	count=1
fi

# display cpu count
echo $count
