如何通过 shell/bash 检测 386、amd64、arm 或 arm64 操作系统架构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48678152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:49:18 来源:igfitidea点击:
How to detect 386, amd64, arm, or arm64 OS architecture via shell/bash
提问by Justin
I'm looking for a POSIX shell/bash command to determine if the OS architecture is 386
, amd64
, arm
, or arm64
?
我正在寻找 POSIX shell/bash 命令来确定操作系统架构是386
, amd64
, arm
, 还是arm64
?
回答by ephemient
uname -m
prints values such as x86_64
, i686
, arm
, or aarch64
.
打印值,例如x86_64
,i686
,arm
,或aarch64
。
回答by Justin
I went with the following:
我采用了以下方法:
architecture=""
case $(uname -m) in
i386) architecture="386" ;;
i686) architecture="386" ;;
x86_64) architecture="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="arm" ;;
esac