On 8/2/11 10:08 AM, Maarten Billemont wrote: > In the following snippet, I expect the two ls' to give the same output. > However, it appears the process substitution's temporary file sometimes > vanishes for the second. Can someone explain why and whether this is the > desired behavior or not? > > A Linux (2.6.27.6) VM in a QEMU says this: > > # moo() { ls -l "$1"; ls -l "$1"; }; moo >(true) > l-wx------ 1 root root 64 Aug 2 14:00 /dev/fd/63 -> pipe:[245] > ls: cannot access /dev/fd/63: No such file or directory > > A Linux (2.6.32-5-amd64) machine says this: > > # moo() { ls -l "$1"; ls -l "$1"; }; moo >(true) > l-wx------ 1 devel devel 1 Aug 2 16:03 /dev/fd/63 -> pipe:[527968] > l-wx------ 1 devel devel 1 Aug 2 16:03 /dev/fd/63 -> pipe:[527968] > > My Mac says this: > > # moo() { ls -l "$1"; ls -l "$1"; }; moo >(true) > prw-rw---- 0 lhunath staff 0 2 Aug 15:55 /dev/fd/63| > prw-rw---- 0 lhunath staff 0 2 Aug 15:55 /dev/fd/63| > > And the latter two break again when I toss a (true) inbetween the two ls': > > # moo() { ls -al "$1"; (true); ls -al "$1"; }; moo >(true) > l-wx------ 1 devel devel 1 Aug 2 16:06 /dev/fd/63 -> pipe:[528022] > ls: cannot access /dev/fd/63: No such file or directory > > # moo() { ls -al "$1"; (true); ls -al "$1"; }; moo >(true) > prw-rw---- 0 lhunath staff 0 2 Aug 16:07 /dev/fd/63| > ls: /dev/fd/63: Bad file descriptor > > Surely neither case where the FD can no longer be accessed or its file has > disappeared can be correct behavior?
Thanks for the report. It's the subshell that makes the difference here: bash-4.2, and probably earlier versions, is too aggressive about closing file descriptors pointing to process substitutions in the parent process, when they should persist until any executing shell function completes. The first example (the Linux VM) was fixed between bash-4.0 and bash-4.1. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/