delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/05/14/20:42:43

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
X-Authority-Analysis: v=1.0 c=1 a=xe8BsctaAAAA:8 a=GvTvE4g6BM9yrIr2J3gA:9 a=NwdwuTgK7cgRoYgCIc0A:7 a=8236z3J4L0RJKDsWJOeyjCKpIQoA:4 a=eDFNAWYWrCwA:10 a=rPt6xJ-oxjAA:10
Message-ID: <482B86DE.1020700@byu.net>
Date: Wed, 14 May 2008 18:42:06 -0600
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080421 Thunderbird/2.0.0.14 Mnenhy/0.7.5.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com, arnstein AT panix DOT com
Subject: Re: grep raises signal ERR
References: <20080515003601 DOT GA18386 AT panix DOT com>
In-Reply-To: <20080515003601.GA18386@panix.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to David Arnstein on 5/14/2008 6:36 PM:
| #!/bin/bash
| trap "echo '<aborting>' ; exit 1" ERR
| grep -q -e 'foo' < /dev/null
|
| This indicates that grep has raised the signal ERR.

There is no such thing as signal ERR.  Rather, ERR is a special case to
the trap command that means the trap is executed when any simple command
returns non-zero status (in the same cases that set -e would cause the
shell to exit).  'man bash' explains this in more detail.

| 	grep -q -e 'foo' < /dev/null
| is NOT aborting my shell script. It simply returns status 1, which I
| do NOT want to handle by calling exit.

Then don't trap ERR, or else write your script to handle expected non-zero
status.  For example,
~  grep -q -e 'foo' < /dev/null || :
is not a simple command (it uses ||), so it won't trigger the ERR trap nor
cause a 'set -e' shell to exit.

By the way, none of this is cygwin specific.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 AT byu DOT net
volunteer cygwin bash maintainer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgrht4ACgkQ84KuGfSFAYC5/ACgxQCwU3UYiF8AovxrOowF/qTC
0UAAniPYYzMBDdpBJTLlySGupx28drAq
=31ss
-----END PGP SIGNATURE-----

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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