[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: redirection inside a process-substitution
From: |
Chet Ramey |
Subject: |
Re: redirection inside a process-substitution |
Date: |
Tue, 23 Aug 2016 11:00:50 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
On 8/22/16 3:38 PM, helmut.karlowski@ish.de wrote:
> When doing redirection inside a sub-process to a descriptor that is
> redirected to a file the output of the subshell goes into the file.
Child processes created to run subshells inherit open file descriptors
from their parent.
> Now when the same descriptor is again redirected to another descriptor for
> this whole
> command-list, the output of the sub-process goes to the other descriptor.
>
> Except when the subshell is subject to process-substitution: In this
> case the outer redirection has no effect to the sub-process. Why is that?
It has to do when things are processed. Process substitution is not a
command or a redirection: it is a word expansion that expands to a file
name. Word expansions are performed before redirections.
When the process substitution is expanded, nothing has run that changes
file descriptor 3 away from the file (tb.err).
> rm -f tb.err
> exec 3>tb.err
> echo ------ 1 ----------
> (echo 1 1>&3) 3>&1
This is not relevant; the subshell is a command to which the redirection
applies.
> echo ........tb.err ...........
> cat tb.err
> echo ------ 2 ---------
> echo >(echo 2 1>&3) 3>&1
The process substitution is expanded before the redirection (which applies
to the `echo', since that is the command) is performed. When the subshell
starts, fd 3 still points to tb.err.
> echo ------ 3 ---------
> echo >(echo 3 1>&3)
> echo ........tb.err ...........
This redirects file descriptor 1 away from the pipe to the descriptor the
subshell inherits from its parent.
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://cnswww.cns.cwru.edu/~chet/