Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16722
| From | "" <kfm@plushkava.net> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: process substitution error handling |
| Date | 2020-08-06 17:36 +0100 |
| Message-ID | <mailman.1036.1596731802.2739.bug-bash@gnu.org> (permalink) |
| References | (4 earlier) <CAHmME9qNjO+LMxB8py2MDpS2Oprv1mRndgfTXQfXNWyHuwzmjg@mail.gmail.com> <9b358a76-4867-41b9-5a3a-c1892c76b8ee@case.edu> <CAHmME9qHEtsri_jYdqppSXwYFLH3Os06xS7wsM00z2dNgHgwyg@mail.gmail.com> <917bf529-d3cb-6783-326b-c7baa7ca9a2e@archlinux.org> <c87777d1-188f-8353-e646-24c64c243710@plushkava.net> |
On 06/08/2020 17:21, Eli Schwartz wrote:
> On 8/6/20 11:31 AM, Jason A. Donenfeld wrote:
>> That doesn't always work:
>>
>> set -e
>> while read -r line; do
>> echo "$line" &
>> done < <(echo 1; sleep 1; echo 2; sleep 1; exit 77)
>> sleep 1
>> wait $!
>> echo done
I wonder why wait $! doesn't do the job here.
>
> So instead of your contrived case, write it properly. Check the process
> substitution first, and make sure as a bonus you don't run anything if
> if it failed:
>
> set -e
> mapfile -t lines < <(echo 1; sleep 1; echo 2; sleep 1; exit 77)
> wait $!
>
> for line in "${lines[@]}"; do
> echo "$line" &
> sleep 1
> wait $!
> echo done
As Jason appears set on using "set -e -o pipefail", here is another
approach that may be more to his taste:
set -e -o pipefail
{ echo 1; sleep 1; echo 2; sleep 1; exit 77; } | while read -r line; do
echo "$line" &
done
sleep 1
echo done
Of course, the loop will be executed in a subshell, but that can be
averted by shopt -s lastpipe.
--
Kerin Millar
Back to gnu.bash.bug | Previous | Next | Find similar
Re: process substitution error handling "" <kfm@plushkava.net> - 2020-08-06 17:36 +0100
csiph-web