tags:

views:

1168

answers:

5

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.

+2  A: 

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").

shoover
+2  A: 

You could do something like this:

if $(uname -a | grep 'x86_64'); then
  echo "I'm 64-bit"
else
  echo "I'm 32-bit"
fi
hoyhoy
+4  A: 
MACHINE_TYPE=`uname -m`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  # 64-bit stuff here
else
  # 32-bit stuff here
fi
bmdhacks
A: 

Yes, uname -a should do the trick. see: http://www.stata.com/support/faqs/win/64bit.html.

+1  A: 
slot8(msd):/opt # uname -a
Linux slot8a 2.6.21_mvlcge500-electra #1 SMP PREEMPT Wed Jun 18 16:29:33 \
EDT 2008 ppc64 GNU/Linux


Remember, there are other CPU architectures than Intel/AMD...

Kevin Little
not for my company, so I don't have to worry ;-)
Mike Stone