, ,

Ubuntu – 64 bits or 32 bits – Determine the Computer Architecture using bash in the terminal

Using a bash function to determine the CPU architecture: amd64 or i386, x86_64 or i386



function os_cpu_bits() {
    if uname -a | grep "x86_64" 1> /dev/null
    then
       echo "amd64"
    elif  uname -a | grep "i386" 1> /dev/null
    then
       echo "i386"
    else
       echo "unknown"
    fi
}
architecture=$(os_cpu_bits)

echo "$architecture"

# amd64

References

1. http://askubuntu.com/questions/41332/how-do-i-check-if-i-have-a-32-bit-or-a-64-bit-os
2. http://www.linuxjournal.com/content/return-values-bash-functions