Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 440
Dougnukem Avatar asked Nov 22 '10 21:11

Dougnukem


People also ask

What shell does Cygwin use?

The Cygwin installation creates a Bash shell along with a UNIX environment by which you can compile and run UNIX-like programs.

How do I run a bash command in Cygwin?

Therefore, the full command to run Bash in Cygwin is C:\cygwin64\bin\bash.exe -i -l .


2 Answers

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
like image 88
PleaseStand Avatar answered Oct 27 '22 00:10

PleaseStand


This works with ksh and bash.

#!/bin/ksh
case "$(uname -s)" in
    CYGWIN*) echo This is Cygwin ;;
    *) echo This is not Cygwin ;;
esac
like image 31
lit Avatar answered Oct 27 '22 00:10

lit