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

后端 未结 11 897
忘掉有多难
忘掉有多难 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:54

    # This script fragment emits Cygwin rulez under bash/cygwin
    if [[ $(uname -s) == CYGWIN* ]];then
        echo Cygwin rulez
    else 
        echo Unix is king
    fi
    

    If the 6 first chars of uname -s command is "CYGWIN", a cygwin system is assumed

提交回复
热议问题