[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to terminate the main process when error arises in p
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] How to terminate the main process when error arises in process substitution? |
Date: |
Tue, 23 Apr 2013 09:04:17 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Apr 22, 2013 at 04:40:06PM -0500, Peng Yu wrote:
> function error {
> echo Hello
> return 1
> }
> echo xx <(error || exit $?)
> echo $?
You can't "exit" the main script from within a background command, which
is what a process substitution is. If you want to check the exit status
of a background job and then react to it, you need to abandon the
process substitution syntax and do things manually.
trap 'rm -f myfifo' EXIT
mkfifo myfifo
mybackgroundjob > myfifo & pid=$!
myforegroundjob < myfifo
wait $pid || { echo "aborting: background job failed" >&2; exit 1; }
echo "I did not abort"