delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/04/05/18:50:47

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=1.7 required=5.0 tests=AWL,BAYES_20,FREEMAIL_FROM,KAM_THEBAT,KHOP_THREADED,TW_YG
X-Spam-Check-By: sourceware.org
Date: Fri, 6 Apr 2012 02:40:56 +0400
From: Andrey Repin <anrdaemon AT freemail DOT ru>
Reply-To: Andrey Repin <cygwin AT cygwin DOT com>
Message-ID: <1948372625.20120406024056@mtu-net.ru>
To: Eric Blake <eblake AT redhat DOT com>, cygwin AT cygwin DOT com
Subject: Re: Is this supposed to work this way?
In-Reply-To: <4F7C4CD2.3090005@redhat.com>
References: <0105D5C1E0353146B1B222348B0411A20A6536CB91 AT NIHMLBX02 DOT nih DOT gov> <602324786 DOT 20120404044708 AT mtu-net DOT ru> <4F7B9C81 DOT 4060209 AT redhat DOT com> <696106181 DOT 20120404053558 AT mtu-net DOT ru> <4F7BC6B1 DOT 8030506 AT etr-usa DOT com> <103388385 DOT 20120404130124 AT mtu-net DOT ru> <4F7C4CD2 DOT 3090005 AT redhat DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Greetings, Eric Blake!

>> Well, then, following your wisdom, I have to clog every line of my script with
>> "... || exit" or an equivalent.

> No, you don't.  You can factor out your feature checks up front, in a
> way that still works with 'set -e', rather than having to give up 'set
> -e' through the entire script.  That said...

>> 
>> Because even an attempt to continue execution, if any error occured, would be
>> disastrous to the calling program.
>> Solution is to "set -e" and have script bail out at any problem,

> 'set -e' is a can of worms, best avoided if you don't want surprises.
> Consider:

> f() { set -e; false; echo hi; }
> f || echo bye

> It does NOT exit on the false.  Rather, it prints 'hi' and NOT 'bye',
> all while turning on set -e for the rest of your script.  And that
> behavior is mandated by POSIX.  My opinion is that you are better off
> coding without 'set -e' in the first place.

Well, this is interesting...

>> but if I try
>> autoconf approach and blindly run whatever I feel appropriate, hoping for the
>> best and preparing for worst, I won't have such option.

> Give us more details of a feature you're trying to test.  I'll even get
> you started with an example - suppose you want to know when to use cygpath:

> if (cygpath --version) >/dev/null 2>&1; then
>   my_convert() { cygpath "$1"; }
> else
>   my_convert() { echo "$1"; }
> fi

> foo "$(my_convert "$file")"

For provided STC, that would be enough. But the script I've striped it from is
reassembling Java application file. And if any step of preparation would fail,
it should not try to assemble it. The difference between Cygwin/Linux/Mac is
just the first stop in there.
I'll have to think about that some day, when I don't have a headache.
May be make OS-specific checks before blowing the horn, if I don't find more
elegant solution... (As I said already, I've hit a stall with readlink on Mac.)

> which will run cygpath on $file on cygwin, and will use $file unchanged
> on other platforms.  And there you have a feature check - you checked
> the feature of whether cygpath exists as an executable up front, then
> the rest of your script is now OS-independent by relying on your
> up-front setup based on the results of the feature check.



--
WBR,
Andrey Repin (anrdaemon AT freemail DOT ru) 06.04.2012, <02:20>

Sorry for my terrible english...


--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019