bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: failed grep should cause subshell to exit


From: Bob Proulx
Subject: Re: failed grep should cause subshell to exit
Date: Mon, 26 Aug 2013 23:23:41 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

David Lehmann wrote:
> > Subject: Re: failed grep should cause subshell to exit
> > set -ex

Insert much previous discussion, search the archives, about why set -e
is really a terrible paradigm for the shell.  Here is a reference.

  http://mywiki.wooledge.org/BashFAQ/105

If you want the shell to exit due to the grep condition then I
recommend coding it explicitly.

  if grep foo file; then
    echo "foo found"
    exit 1
  fi

  if ! grep foo file; then
    echo "foo not found"
    exit 1
  fi

  grep foo file && { echo "foo found"; exit 1 ;}

  grep foo file || { echo "foo found"; exit 1 ;}

All are better style (yes, I know it is a matter of taste) than trying
to use 'set -e' as a catch-all.  Because 'set -e' is what it is and is
what it has been for decades.  That ship sailed years ago.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]