First of all, I think @Michael Krelin is right about the fact that this is due to the bash version shipped with OS X (v3.2.48). From my testing it can be seen that the file descriptors are discarded after the first external command executed by the function:
$ bar() { echo "Args: $*"; echo "First ext command:"; ls /dev/fd; echo "Second ext command:"; ls /dev/fd; } $ bar <(echo hi) <(echo bye) Args: /dev/fd/63 /dev/fd/62 First ext command: 0 1 2 3 4 5 6 62 63 Second ext command: 0 1 2 3 4 5 6
Note that / dev / fd / 62 and 63 disappear between the two ls lists. I think I found a workaround: copy the fragile fd to the non-fragile fd before they can disappear:
$ baz() { exec 3<"$1" 4<"$2"; ls /dev/fd; ls /dev/fd; cat /dev/fd/3; cat /dev/fd/4; } $ baz <(echo hi) <(echo bye) 0 1 2 3 4 5 6 62 63 0 1 2 3 4 5 6 hi bye
source share