Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

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.

like image 919
Mike Stone Avatar asked Sep 19 '08 23:09

Mike Stone


People also ask

How do I know if my Linux file is 32-bit or 64-bit?

If you're interested in the CPU itself, look at /proc/cpuinfo for details about the CPU(s) detected by the Linux kernel. which tells us that it's a 32-bit executable using the Intel 80386 instruction set (possibly with extensions). Note that it isn't quite as simple as 32-bit versus 64-bit architectures.

How can I tell if a LIB file is 64-bit?

Therefore, the “/usr/lib/libc-2.33.so” file is a 64-bit library and the other one is a 32-bit library. Also, if we have a look at their “start address” fields, they have 64-bit and 32-bit wide addresses respectively.

What does $2 mean in a bash shell script?

$2 is the second command-line argument passed to the shell script or function. Also, know as Positional parameters.


2 Answers

MACHINE_TYPE=`uname -m` if [ ${MACHINE_TYPE} == 'x86_64' ]; then   # 64-bit stuff here else   # 32-bit stuff here fi 
like image 111
bmdhacks Avatar answered Sep 24 '22 01:09

bmdhacks


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

like image 22
shoover Avatar answered Sep 20 '22 01:09

shoover