How to check if running in Cygwin, Mac or Linux?

后端 未结 11 898
忘掉有多难
忘掉有多难 2020-11-27 23:58

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

How can a shell/bash script de

11条回答
  •  猫巷女王i
    2020-11-28 00:58

    I guess the uname answer is unbeatable, mainly in terms of cleanliness.

    Although it takes a ridiculous time to execute, I found that testing for specific files presence also gives me good and quicker results, since I'm not invoking an executable:

    So,

    [ -f /usr/bin/cygwin1.dll ] && echo Yep, Cygwin running

    just uses a quick Bash file presence check. As I'm on Windows right now, I can't tell you any specific files for Linuxes and Mac OS X from my head, but I'm pretty sure they do exist. :-)

提交回复
热议问题