bug-bash
[Top][All Lists]
Advanced

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

Re: process substitution and trailing file descriptors


From: Marc Herbert
Subject: Re: process substitution and trailing file descriptors
Date: Fri, 12 Feb 2010 13:06:59 +0000
User-agent: Thunderbird 2.0.0.23 (X11/20090825)

Ian wrote:
>  The manual suggests I could move and close file descriptors with
> 
>  [n]>&digit-
> 
>  but I would need the equivalent of
> 
>  command1 >&>(...)-
> 
>  Digit might very well mean (just a) digit but here the process
> substitution, of course, is replaced with /dev/fd/63, say, certainly
> not a digit.
 
What about something like this (highly non-portable):

run_with_tee()
{
    _run_with_tee  >(tee out)  "$@"
}

_run_with_tee()
{
    local fdpipeout=${1#/proc/self/fd/}; shift
    # Redirect+close not to leak the extra pipe FD
    >&$fdpipeout- "$@"
}

run_with_tee someCommand


Greg Wooledge wrote:
> When the shortcuts are too short, you need to fall back to the original
> tools.  In this case, >() is really just a shortcut for "create a FIFO,
> and open it".  Doing so by hand should give you the manual control you
> need.  At the very least, you can tell bash which FD number to use when
> you open the FIFO.

Yeah, but then you have the hassle to cleanup/delete the FIFO by yourself.
And leave tons of them behind in case of errors.






reply via email to

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