bug-bash
[Top][All Lists]
Advanced

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

Re: Process Substitution subshell inherits the desire to print its times


From: Chet Ramey
Subject: Re: Process Substitution subshell inherits the desire to print its times if it contains explicit exit
Date: Wed, 4 Apr 2018 14:36:02 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 4/4/18 4:21 AM, Basin Ilya wrote:
> Hi.
> 
> In an attempt to capture the output of 'time' I used the process substitution 
> and noticed that the subshell also prints its times. Actually I this happens 
> when I redirect any fd, not just stderr.

It's an interaction between command timing and the `exit' builtin wanting
to make sure it does things like run any exit trap. The file descriptor
manipulation doesn't matter; it's the process substitution subshell
creation that does it. A command like `cat <( echo procsub ; exit 0)'
would work just as well. I'll take a look at the best way to fix it.

> 
>     #!/bin/bash
> 
>     time {
>       sleep 0.25
>       exec 6> >(
>         sed 's/^/captured: /'
>         exit 0
>       )
>     }
> 
>     # close write side of the pipe and wait for reader
>     exec 6>&-
>     wait $!
> 
> 

> Earlier bash versions just print: wait: pid 28717 is not a child of this shell

Bash-4.4 allows wait to reap the last process substitution created, since
it sets $!.

Chet
-- 
``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]