从命令行检测 Apple Silicon [英] Detect Apple Silicon from command line

查看:31
本文介绍了从命令行检测 Apple Silicon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 shell 脚本中检测到它在 M1 Apple 硬件上运行?

How can I detect from a shell script that it is running on M1 Apple hardware?

我希望能够运行命令行命令,以便我可以编写一个 if 语句,该语句的主体仅在具有 M1 处理器(至少是 macOS)的 mac 上运行时才会执行自然是 Bug Sur).

I want to be able to run a command line command so that I can write an if-statement whose body will only be executed when run on a mac with an M1 processor (and at least macOS Bug Sur, naturally).

推荐答案

uname -m

将返回 arm64 而不是 x86_64

if [[ `uname -m` == 'arm64' ]]; then
  echo M1
fi

或者,正如@chepner 建议的

or, as @chepner suggested

uname -p

将返回 arm 而不是 i386

if [[ $(uname -p) == 'arm' ]]; then
  echo M1
fi

这篇关于从命令行检测 Apple Silicon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆