EN
Bash - detect machine architecture (Intel/AMD, x86/x64, 32bit/64bit)
8
points
In this short article, we would like to show how to check used machine architecture (Intel/AMD, x86/x64, 32bit/64bit) under Bash.
⚠️ Warning ⚠️: this solution works only for x86/x64 processors.
Quick solution:
#!/bin/bash
case "$(uname -m)" in
amd64) echo '64bit' ;;
x86_64) echo '64bit' ;;
i686-64) echo '64bit' ;;
x86) echo '32bit' ;;
x86pc) echo '32bit' ;;
i386) echo '32bit' ;;
i686) echo '32bit' ;;
i686-AT386) echo '32bit' ;;
# ...
# Add other cases here ...
# ...
*) echo 'unknown' ;;
esac
Alternative solution
arch
command prints machine hardware name same as uname -m
command.
#!/bin/bash
case "$(arch)" in
amd64) echo '64bit' ;;
x86_64) echo '64bit' ;;
i686-64) echo '64bit' ;;
x86) echo '32bit' ;;
x86pc) echo '32bit' ;;
i386) echo '32bit' ;;
i686) echo '32bit' ;;
i686-AT386) echo '32bit' ;;
# ...
# Add other cases here ...
# ...
*) echo 'unknown' ;;
esac