bug-bash
[Top][All Lists]
Advanced

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

Re: process substitution error handling


From: Chet Ramey
Subject: Re: process substitution error handling
Date: Thu, 6 Aug 2020 11:14:40 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 8/6/20 10:48 AM, Chet Ramey wrote:

>> Perhaps another, clunkier, proposal would be to add `wait -s` so that
>> the wait builtin also waits for process substitutions and returns
>> their exit codes and changes $?. The downside would be that scripts
>> now need to add a "wait" after all of above such loops, but on the
>> upside, it's better than the current problematic situation.
> 
> You can already do this. Since process substitution sets $!, you can
> keep track of all of the process substitutions of interest and wait
> for as many of them as you like. `wait' will return their statuses
> and set $? for you.

I should have also mentioned that while bash-5.0 requires you to wait
for these process substitutions one at a time, in between their creation,
bash-5.1 will allow you to save $! and wait for them later:

$ cat x2
: <(sleep 5; exit 1)
P1=$!

: <(sleep 5; exit 2)
P2=$!

: <(sleep 5; exit 3)
P3=$!

wait $P1 ; echo $?
wait $P2 ; echo $?
wait $P3 ; echo $?
$ ../bash-5.1-alpha/bash x2
1
2
3


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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