bug-bash
[Top][All Lists]
Advanced

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

Re: redirection inside a process-substitution


From: Pierre Gaston
Subject: Re: redirection inside a process-substitution
Date: Tue, 23 Aug 2016 14:57:48 +0300



On Mon, Aug 22, 2016 at 10: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.

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?

Example:

rm -f tb.err
exec 3>tb.err
echo ------ 1 ----------
(echo 1 1>&3) 3>&1
echo ........tb.err ...........
cat tb.err
echo ------ 2 ---------
echo >(echo 2 1>&3) 3>&1
echo ........tb.err ...........
cat tb.err
echo ------ 3 ---------
echo >(echo 3 1>&3)
echo ........tb.err ...........
cat tb.err

Only test 3 should print 3 into tb.err. bash and ksh93 also print
into tb.err in test 2, which is inconsistent compared to case 1. What's so
special about process-substitution regarding redirection?

-Helmut

Case 1 is totally different from the other two. 3>&1 redirects the fds for the coumpound command (  )
 
Case 2 is not really special, the redirection applies to the command (the first echo) not to its arguments in the same way  echo $(echo 4 1>&3) 3>&1 prints in the file

There is also another case that may be interesting:

echo 3>&1 > >(echo 5 1>&3) 

in which 5 is not printed in the file, which makes sense to me as the process substitution is part of the redirections and not of the arguments.



reply via email to

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