help-bash
[Top][All Lists]
Advanced

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

Re: Check the error status of process substitution


From: Masahiro Yamada
Subject: Re: Check the error status of process substitution
Date: Tue, 7 Jun 2022 03:25:49 +0900

Hi.

Thank you for the reply.


On Tue, Jun 7, 2022 at 3:05 AM Greg Wooledge <greg@wooledge.org> wrote:
>
> On Tue, Jun 07, 2022 at 02:35:27AM +0900, Masahiro Yamada wrote:
> > "wait $!" does not seem to work in old bash versions.
> >
> > So, I guess something was fixed between
> > v4.3.48 and v4.4.20 but it looks like
> > some people are still using old bash versions.
>
> Yes, the feature you're looking for was added in bash 4.4.
>
> If you need the exit status of a background job in earlier versions
> of bash, you have a few alternative options.  You can create a named
> pipe, and have a "regular" background job (one launched with & after it)
> write to that.  Then you can use wait on the job's PID afterward.

Worked for me.
(but I do not like to modify the system...)


> Or, if you still want to use a process substitution, you can have it
> write its exit status to a temporary file, and then retrieve the value
> from the temporary file in the main script.
>

My main motivation for using a process substitution is
to reflect variable changes made in the loop
(like 'nr_lines' in the sample code)
to the outside of the loop.

A pipe does not work that way
since the loop is executed in a subshell.





-- 
Best Regards
Masahiro Yamada



reply via email to

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