bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: process substitution error handling


From: Eli Schwartz
Subject: Re: process substitution error handling
Date: Thu, 6 Aug 2020 13:09:23 -0400

On 8/6/20 12:36 PM, kfm@plushkava.net wrote:
> 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.

Because `echo "$line" &` sets a new value for $! after the <() did.

More to the point, you want to wait $! *before* running any commands in
the while loop, because if the <() failed, it might not be a good idea
to run those commands.

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]