X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-10.2 required=5.0 tests=AWL,BAYES_00,KHOP_PGP_SIGNED,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_YG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4F7C4CD2.3090005@redhat.com> Date: Wed, 04 Apr 2012 07:29:54 -0600 From: Eric Blake User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Is this supposed to work this way? 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> In-Reply-To: <103388385.20120404130124@mtu-net.ru> OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigE86F55887B8901F4EA487E64" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: 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 --------------enigE86F55887B8901F4EA487E64 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 04/04/2012 03:01 AM, Andrey Repin wrote: >=20 > 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... >=20 > Because even an attempt to continue execution, if any error occured, woul= d 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. > 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")" 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. --=20 Eric Blake eblake AT redhat DOT com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigE86F55887B8901F4EA487E64 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPfEzSAAoJEKeha0olJ0NqPXIH/1C06ywHdS9vWGtXsIDn0pQ0 i4Ma0xblxyLqy4OxX93n/ZF/lw8jNBHNrRVcKWYbQtbFrxw1jptqWhTpvQftXBO4 XpfV+W/yUUG22f9rtsviEpdN9yacI7ZAirOytTzJn+D1bLFohKXAQDt2z7ebRgnD iifpPem0ea2YFc4FIpUBuGMZ4V4tA6rA4HNdjVXbTRgCWlg1M0jc90J7+SW6uyE+ yVxlLGe/h3EDJNj3IMZN+nDpAvBVlTUcN3p0ytB6iMlfTyO4jEhCvQjUhnsVHR97 NpC6YROQNYXk4VCRjcwrWJqlEZeD6SeNlDj+i+1Dw7V6hSYU9ZE781b3Ki1o+C4= =t1f1 -----END PGP SIGNATURE----- --------------enigE86F55887B8901F4EA487E64--