本文介绍了如何检查是否在Cygwin中,Mac或Linux上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个同时使用在Windows / Cygwin和Mac和Linux shell脚本。它需要为每个版本稍有不同的变量。

I have a shell script that is used both on Windows/Cygwin and Mac and Linux. It needs slightly different variables for each versions.

如何能一个shell / bash脚本检测无论是在Cygwin中运行,在Mac或Linux中?

How can a shell/bash script detect whether it is running in Cygwin, on a Mac or in Linux?

推荐答案

通常情况下,的uname 有各种选项会告诉你,你在运行的环境:

Usually, uname with its various options will tell you what environment you're running in:

pax> uname -a
CYGWIN_NT-5.1 IBM-L3F3936 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin

pax> uname -s
CYGWIN_NT-5.1

pax> uname -o
Cygwin

不幸的是,我没有Linux或Mac得心应手这样别人会要添加这些。

Unfortunately, I don't have a Linux or Mac handy so someone else will have to add those.

据很有帮助散粒,的uname -s 达尔文的OSX和 Linux的用于Linux和我的Cygwin给 CYGWIN_NT-5.1 。但是,你可能有各种不同版本进行试验。

According to the very helpful schot, uname -s gives Darwin for OSX and Linux for Linux and my Cygwin gives CYGWIN_NT-5.1. But you'll probably have to experiment with all sorts of different versions.

这篇关于如何检查是否在Cygwin中,Mac或Linux上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:20