Languages
[Edit]
EN

Bash - detect machine architecture (Intel/AMD, x86/x64, 32bit/64bit)

8 points
Created by:
Pearl-Hurley
559

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

 

See also

  1. Bash - detect operating system

References

  1. Uname - Wikipedia
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join