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 [email protected]
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html