Portable shell code between Cygwin and Linux

Eliot Moss moss@cs.umass.edu
Tue Aug 2 15:41:00 GMT 2011

On 8/2/2011 8:24 AM, Sebastien Vauban wrote:
> Hi Thorsten,
> Thorsten Kampe wrote:
>> * Sebastien Vauban (Mon, 01 Aug 2011 08:46:52 +0200)
>>> My goal is to have just 1 alias that would work both under Win32
>>> (Cygwin) and Ubuntu
>> Why don't have simply put your alias definitions in if [[ $OSTYPE =
>> cygwin ]]; then else"?
> Because I really want one single definition which could work on every system
> I'm using.
> I don't like copy/pasting things, and just changing bits of the code, if I can
> avoid it.
> And this is not only for aliases. I'd like my shell scripts in general to be
> able to run in whichever PC I'm on, be it Ubuntu or Windows.

I get that -- I really do.  The suggestion to use a few conditionals
that look at the which OS you're on does not involve continued tweaking.
Once you have the right file, it works everywhere (for which you have
provided suitable cases) using the exact same file. It's just that
different parts get executed on different platforms.  It's not as
elegant as achieving an arrangement with no conditionals, but it's
practical and flexible. I've done it for years myself!

Regards -- Eliot Moss

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

More information about the Cygwin mailing list