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 detect whether it is running in Cygwin, on a Mac or in Linux?
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 detect whether it is running in Cygwin, on a Mac or in Linux?
Usually, uname with its various options will tell you what environment you're running in:
pax> uname -a
CYGWIN_NT-5.1 IBM-L3F3936 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin
pax> uname -s
CYGWIN_NT-5.1
pax> uname -o
Cygwin
Unfortunately, I don't have a Linux or Mac handy so someone else will have to add those.
According to the very helpful schot, uname -s gives Darwin for OSX and Linux for Linux and my Cygwin gives CYGWIN_NT-5.1. But you'll probably have to experiment with all sorts of different versions.
If uname, as suggested by paxdiablo, gives not enough information, you can check for existence of some specific files, e.g.,/Applications/iPhoto.app/ directory on Mac OS X.
http://en.wikipedia.org/wiki/Uname
All the info you'll ever need. Google is your friend.