Is it possible to detect 32 bit vs 64 bit in a bash script?


Question

I am writing a bash script to deal with some installations in an automated way... I have the possibility of getting one such program in 32 or 64 bit binary... is it possible to detect the machine architecture from bash so I can select the correct binary?

This will be for Ubuntu machines.

1
69
9/19/2008 11:29:36 PM

Accepted Answer

Does

uname -a

give you anything you can use? I don't have a 64-bit machine to test on.


Note from Mike Stone: This works, though specifically

uname -m

Will give "x86_64" for 64 bit, and something else for other 32 bit types (in my 32 bit VM, it's "i686").

48
9/19/2008 11:38:35 PM

MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  # 64-bit stuff here
else
  # 32-bit stuff here
fi

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon