[Top][All Lists]

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

Re: feature request: more complete set -e

From: Bob Proulx
Subject: Re: feature request: more complete set -e
Date: Mon, 29 Jun 2009 10:28:08 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

Chet Ramey wrote:
> It depends on what you mean by `fail'.
> ...
> To do otherwise would have made expr much less useful.  Idioms such as

Also I must mention grep too.  The exit status of grep isn't just
whether it exits without an error but instead returns an indication of
whether the pattern matched or not.  This makes idioms such as this

  if grep -q PATTERN FILE; then
    ... do something ...

But if used by itself as a filter the exit status may be non-zero and
that isn't an error condition.  I have seen a lot of people run into
'set -e' and grep collisions.


Which is why I like to use sed for this instead.  Then the exit code
reflects errors and not pattern matches and can be more easily used to
handle errors such as a full disk.

  sed -n '/PATTERN/p' FILE1 > FILE2 || exit 1


reply via email to

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