This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Cygwin for Fedora?

> Hello,
> Was wondering if it's possible to install / emulate Cygwin on Fedora?
> Basically, I want my scripts to be able to run flawlessly on both Fedora
> and
> Cygwin/Windows systems. Cygwin, I believe, can have different packages
> and/or
> different versions of programs in packages (e.g. /usr/bin/file, whose
> output for
> Microsoft documents changes with versions).
> Instead of asking for access to a Cygwin/Windows PC just for the above, I
> thought it would be terrific if Cygwin could somehow be installed /
> emulated on
> a Fedora.
> Regards,
> /HS
Harry -

I understand what you are asking for and it is a special case of wanting to
have the same shell scripts run in a Windows (e.g. Cygwin) and other UNIX
environments:  e.g. Linux, Solaris, HP/UX and AIX to name a few.    
As you point out many commands with the same name actually have different
behaviors in different environments.  There are many ways this can be
handled and at the risk of starting a debate as to what is the best way, I
will give you one alternative that I have used successfully many times.

I create a file named which contains functions common to all my
scripts and functions which abstract out the differences between platforms.
This file is read into all my scripts using something like the following.

$BINDIR=`dirname` $0`  
. "$BINDIR"/

This assumes that all your scripts are in the same directory, but if not you
get the idea.

One key function in is:

setplat () {
        # Set the location of UNIX commands and the
        # names of some UNIX command.  And some common
        # common parameters.

        # Set default name of awk command

        # Set the OS specific parameters
        set `uname -a`
        case $OSVERSION in
                SunOS*) PATH=/usr/bin
                        # Solaris hostname is a FQDN! Strip DN.

                Linux*) PATH=/bin:/usr/bin
                        HOSTNAME=`hostname -s`

                 # Other platforms removed for clarity.

# Now determine where we are executing.

The above is by no means complete, as I have stripped out some stuff to make
it clearer.  Note that in the above the path is set to a restricted set of
directories.  This may not be what you want, but this example, is for a
build system and the construction environment is set elsewhere and refers to
absolute path names to commands used.  This ensures there are no mistakes
that might be made because of similar commands being installed by other

Now here is an example what you might do.  If running in a Windows
environment, some commands might yield a windows path name which should not
be passed into a Cygwin command.  So you define a function get_path which
always returns a POSIX style path.

get_path () {
        case $OSVERSION in
                CYG*)  `cygpath "$1"` ;;
                *)      echo "$1" ;;

And you do things like 


Where you need to be sure you have a POSIX style path

Here's an example of a function that gets the value of the nth field from
standard input.  It deals with the problem of DOS line endings that might
occur in non-Cygwin environments. 

field () {
        # Careful. The stuff in brackets is space tab.
        sed "s/[ 	][ 	]*/|/g" | cut -d"|" -f$1 | sed s/$'\r'//

Now the nice thing about this approach is that all the platform differences
can be isolated / migrated to one place and tuned as you need.


Andy Hall

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]