All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <ebb9@byu.net>
To: Peter Jakobi <jakobi@acm.org>
Cc: dash@vger.kernel.org
Subject: Re: Feature request: set -o pipefail
Date: Wed, 12 Aug 2009 06:51:21 -0600	[thread overview]
Message-ID: <4A82BAC9.9040808@byu.net> (raw)
In-Reply-To: <20090807131833.GA30733@anuurn.compact>

According to Peter Jakobi on 8/7/2009 7:18 AM:
> implement  set  -o pipefail. This will allow the user to  request  the
> return  code  to be the one of the first pipe command with a  non-zero
> error. 

That just seems like bloat to me.  Not to mention that it can lead to
surprising results due to SIGPIPE (that is, there are cases where 'command
| head' should be considered successful, even though command exited from
SIGPIPE, where using bash's 'set -o pipefail' will make it look like a
failure).

> The  lack  of  which  can be quite painful in  scripting,  even  if  a
> bourne-shell/posix subset would otherwise be quite sufficient.

You can generally achieve what you want with just the posix subset, which
will make your code more portable in the long run.  Here's one idea:

>    system "set -o pipefail; mv -i foo bar </dev/tty 2>&1 | tee -a LOG";

system "exec 3>&1; s=$(exec 4>&1 >&3; { mv -i foo bar </dev/tty 2>&1; echo
$? >&4; } | tee -a LOG) && exit $s"

Basically, save the original stdout in fd 3, then use a command
substitution where we save the substitution's stdout in fd 4, restore the
original stdout, and perform the pipe.  Then, by modifying the first
command of the pipe to feed the result of the command substitution, we are
now able to guarantee non-zero status if either (or both) the mv or tee fail.

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

Eric Blake             ebb9@byu.net

  reply	other threads:[~2009-08-12 12:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-07 13:18 Feature request: set -o pipefail Peter Jakobi
2009-08-12 12:51 ` Eric Blake [this message]
2009-08-13 14:35   ` Peter Jakobi
2009-08-13 23:15     ` Oleg Verych

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A82BAC9.9040808@byu.net \
    --to=ebb9@byu.net \
    --cc=dash@vger.kernel.org \
    --cc=jakobi@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.