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

Re: Duplicating file descriptor 10



On Thu, Oct 15, 2026 at 7:42 PM John Pell <john@xxxxxxxxxxxxxxxx> wrote:
>
> Zsh duplicates the tty (from stdin) to fd 10, which is exactly what I’m looking for, except… I can’t write to fd 10. I can’t dup fd 10.

Zsh reserves the first available fd greater than 9 to be its internal
copy of fd 0 because it sometimes needs to dup it back to 0 again for
proper operation.  It therefore protects it from being manipulated by
shell redirections, and forces errno = EBADF if you try.  Note this
isn't always fd 10, if the calling process has opened 10 and left it
that way, this reserved fd moves to 11.

> The goal here is to be able to print to the tty even if stdin/stdout/stderr are redirected elsewhere at various times.

The reserved fd is not guaranteed to be connected to a TTY, though it
would be in an interactive shell.




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