[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
process substitution error handling
From: |
Jason A. Donenfeld |
Subject: |
process substitution error handling |
Date: |
Thu, 6 Aug 2020 12:05:49 +0200 |
Hi,
It may be a surprise to some that this code here winds up printing
"done", always:
$ cat a.bash
set -e -o pipefail
while read -r line; do
echo "$line"
done < <(echo 1; sleep 1; echo 2; sleep 1; false; exit 1)
sleep 1
echo done
$ bash a.bash
1
2
done
The reason for this is that process substitution right now does not
propagate errors. It's sort of possible to almost make this better
with `|| kill $$` or some variant, and trap handlers, but that's very
clunky and fraught with its own problems.
Therefore, I propose a `set -o substfail` option for the upcoming bash
5.1, which would cause process substitution to propagate its errors
upwards, even if done asynchronously.
Chet - thoughts?
It'd certainly make a lot of my scripts more reliable.
Jason
Re: process substitution error handling, Chet Ramey, 2020/08/06