在 Cygwin 中获取 Windows 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6176833/
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-15 16:57:44  来源:igfitidea点击:

Get windows version in Cygwin

windowsbashscriptingcygwin

提问by Sedrik

How can I get the windows version I am currently running under Cygwin?

如何获得我目前在 Cygwin 下运行的 Windows 版本?

I am maintaining a automatic build script that is running on Mac, Windows and Linux distributions and I need to be able to detect what Windows version it is currently running under.

我正在维护一个在 Mac、Windows 和 Linux 发行版上运行的自动构建脚本,我需要能够检测它当前正在运行的 Windows 版本。

Preferably I could have it return the standard Windows release name but some kind of code that I can separate from the other ones would also be great.

最好我可以让它返回标准的 Windows 版本名称,但我可以与其他代码分开的某种代码也很棒。

What I want to know is if I am running 7, XP, Server 2008 and so on.

我想知道的是,如果我运行的是 7、XP、Server 2008 等等。

Help, Ideas?

帮助,想法?

采纳答案by Ekkehard.Horner

Like this:

像这样:

eh@winxpsp3 ~
$ echo `cmd /c ver`
 Microsoft Windows XP [Version 5.1.2600]

eh@winxpsp3 ~
$

回答by Costa

You can grep it out of the Windows systeminfoutility.

您可以从 Windowssysteminfo实用程序中提取出它。

systeminfo | grep '^OS'

OS name only:

仅操作系统名称:

systeminfo | sed -n 's/^OS Name:[[:blank:]]*//p'

Example:

例子:

$ systeminfo.exe | grep '^OS'
OS Name:                   Microsoft Windows 7 Home Premium
OS Version:                6.1.7601 Service Pack 1 Build 7601
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
$ systeminfo | sed -n 's/^OS Name:[[:blank:]]*//p'
Microsoft Windows 7 Home Premium

回答by keyboardP

You could use uname -sand compare the output to this:

您可以使用uname -s并将输出与此进行比较:

NT-5.0 = W2000

NT-5.1 = XP

NT-6.0 = Vista

NT-6.1 = W7

NT-5.0 = W2000

NT-5.1 = XP

NT-6.0 = Vista

NT-6.1 = W7

I'm running Windows 7 64 bit, so my output is: CYGWIN_NT-6.1-WOW64. You can see more information here.

我正在运行 Windows 7 64 位,所以我的输出是: CYGWIN_NT-6.1-WOW64. 您可以在此处查看更多信息。