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

后端 未结 11 877
忘掉有多难
忘掉有多难 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条回答
  •  攒了一身酷
    2020-11-28 00:52

    Windows Subsystem for Linux did not exist when this question was asked. It gave these results in my test:

    uname -s -> Linux
    uname -o -> GNU/Linux
    uname -r -> 4.4.0-17763-Microsoft
    

    This means that you need uname -r to distinguish it from native Linux.

提交回复
热议问题