Search code examples
windowsbashunixshellcygwin

Shell script detecting running in Cygwin


Is there a simple way to check if a script is running in Cygwin. We have a script that calls a utility that expects the paths passed to be windows so if we're in Cygwin we have to convert the paths to windows paths.


Solution

  • You can use the uname utility. From uname(1):

    -o, --operating-system
    print the operating system

    Example code:

    if [ `uname -o` = "Cygwin" ]
    then
        # Cygwin specific stuff
    else
        # Other UNIX (Linux, etc.) specific stuff
    fi