X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=0.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org From: "Andy Hall" To: , References: <4F586390 DOT 6080702 AT gmail DOT com> Subject: RE: Cygwin for Fedora? Date: Sat, 10 Mar 2012 15:44:13 -0800 Message-ID: <4C389F5B9A5340CFAB7F5BA70D7AB62C@ahallpc> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <4F586390.6080702@gmail.com> X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com > > 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 common.sh 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"/common.sh This assumes that all your scripts are in the same directory, but if not you get the idea. One key function in common.sh 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 AWK_CMD=awk # Set the OS specific parameters set `uname -a` OSVERSION=$1$3 case $OSVERSION in SunOS*) PATH=/usr/bin AWK_CMD=nawk PLATFORM=SunOS HOSTNAME=`hostname` # Solaris hostname is a FQDN! Strip DN. HOSTNAME=${HOSTNAME%%[.]*} ;; Linux*) PATH=/bin:/usr/bin PLATFORM=Linux HOSTNAME=`hostname -s` ;; CYG*) PLATFORM=WINNT ;; # Other platforms removed for clarity. esac } # Now determine where we are executing. setplat 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 packages. 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" ;; esac } And you do things like SOURCE_ROOT=`get_path "$SOURCE_ROOT"` 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. HTH Andy Hall -- 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