Possible Duplicate:
How to determine whether a given Linux is 32 bit or 64 bit?
Does anybody know how to create a shell script sh file that can shell one program if its a 64-bit system or shell another if its a 32-bit system? Thank so much.
Possible Duplicate:
How to determine whether a given Linux is 32 bit or 64 bit?
Does anybody know how to create a shell script sh file that can shell one program if its a 64-bit system or shell another if its a 32-bit system? Thank so much.
if $(uname -m | grep '64'); then
echo "ARCH: 64-bit"
else
echo "ARCH: 32-bit"
fi
Try uname -m
: x86_64
is a 64-bit kernel, i686
is 32-bit kernel. Based on this, you can call either one program or the other.
(In response to thkala's comment.)
if echo __SIZEOF_POINTER__ | cpp -E - - | grep '^8$' >/dev/null; then
do_stuff
fi
Unlikely to work everywhere, but it works if cpp is from GCC. Has the advantage of detecting any 64-bit architecture, not just x64 (POWER, SPARC, IA64, whatever).
If you want to know whether the processor is 64-bit, rather than the kernel, You can search for the long mode (-lm) flag on your system. It will be present on 64-bit, and not on 32-bit:
cat /proc/cpuinfo | grep lm