On Tue, Feb 12, 2013 at 6:07 PM, Matei David <matei.da...@gmail.com> wrote:
> Ok, but I see the same behaviour when eval runs in a subshell: > > $ bash -c 'llfd () { echo "pid:$BASHPID" >&2; ls -l /proc/$BASHPID/fd/ > >&2; }; x=3; eval "exec $x>/dev/null"; llfd; echo | eval "llfd $x>&-"' > [same output, fd 10 open, pointing to /dev/null, even though it's a > subshell] > eval runs in a subshell, but it's the same thing inside this subshell. eg you could have: echo | { eval "llfd "$x>&-"; echo blah >&3; } Bash could optimize this once it realizes there's only one command, but it's probably not that simple to implement. Try with a function that spawns a subshell eg: llfd () ( echo "pid:$BASHPID" >&2; ls -l /proc/$BASHPID/fd/ >&2; ) or llfd () { bash -c 'ls -l /proc/$$/fd' ; }