Is this supposed to work this way?

Eric Blake
Wed Apr 4 13:30:00 GMT 2012

On 04/04/2012 03:01 AM, Andrey Repin wrote:

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

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.

> 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"; }
  my_convert() { echo "$1"; }

foo "$(my_convert "$file")"

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.

Eric Blake    +1-919-301-3266
Libvirt virtualization library

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Cygwin mailing list