gpt4 book ai didi

macos - 检查操作系统版本,如果版本正确则发出命令

转载 作者:行者123 更新时间:2023-11-29 09:02:11 25 4
gpt4 key购买 nike

我正在为 Mac OS X Lion 10.7 编写一个 bash 脚本,我想知道如何在 bash 中检查操作系统的版本,如果版本是 10.7.1,那么它会执行一个命令并继续脚本并为不同的版本做同样的事情让我们说 10.7.3 然后它执行一个不同的命令然后用于 10.7.1 的命令?

最佳答案

OS_Version(完整……示例 10.7.3)

system_profiler SPSoftwareDataType | grep "System Version" | awk '{print $6}'

sw_vers -productVersion

操作系统(简称……示例 10.7)

system_profiler SPSoftwareDataType | grep "System Version" | awk '{print $6}' | sed "s:.[[:digit:]]*.$::g"

OS_Version=$(OS (short… example 10.7) | sed "s:.[[:digit:]]*)

狂欢:

#!/bin/bash

# Use one of the examples given above to create the OS_Version variable

if [[ ${OS_Version} == 10.7.3 ]]; then
echo "Operating System is a match... will continue on."
else
echo "Operating System is NOT a match... will NOT continue."
fi

关于macos - 检查操作系统版本,如果版本正确则发出命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9913942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com