Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: process substitution bug?



On Mar 16, 11:43pm, Alexey Tourbin wrote:
}
} When I wrap some command into a function, process substitution
} no longer works:

This is not precisely a bug, it's a limitation of process substitution
and the shell file descriptor management model.

} $ =diff <(echo 1) <(echo 2)

In this case there's a single external command being run; the file
descriptors opened for the process substitutions remain open across
fork(), so diff can reference them via /proc/self/fd/.

} $ diff <(echo 1) <(echo 2)
} /usr/bin/diff: /proc/self/fd/11: No such file or directory
} /usr/bin/diff: /proc/self/fd/12: No such file or directory

Here, the diff function is being executed in the current shell.  The
file descriptors are opened for the shell function and all the shell
builtin commands, but (because they have numbers > 9) they are closed
when external commands are executed within the function.

Replace "diff" with a builtin such as "stat" (zmodload zsh/stat) and
you'll see that the process substitution is working.

It could be argued that descriptors opened by process substitution
should remain open across external command execution within functions;
they do, in e.g. bash.



Messages sorted by: Reverse Date, Date, Thread, Author