可以使用 uname 命令来区分当前系统是 macOS 还是 Linux。
下面是一个示例 shell 脚本,在 macOS 和 Linux 下表现不同:
#!/bin/bash
system=`uname`
if [ "$system" == "Darwin" ]; then
# 这里是 macOS 下的代码
echo "This is macOS"
else
# 这里是 Linux 下的代码
echo "This is Linux"
fi
在执行这个脚本时,如果当前系统是 macOS,则会输出 "This is macOS";如果当前系统
通过运行uname命令并检查输出,此shell脚本能识别系统是macOS还是Linux。当系统为macOS(Darwin内核)时,脚本将打印ThisismacOS,而在Linux系统上则会显示ThisisLinux。
50

被折叠的 条评论
为什么被折叠?



