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

Re: Temporary redirection of named file descriptors



On Tue, Oct 19, 2021 at 12:50 PM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>
> TL;DR: How can I redirect a named file descriptor (to e.g. /dev/null), but only for one statement?

The short answer is that you can't do what you're trying to do in the
way you're trying to do it.  The {myfd}> syntax is defined to create a
new value in $myfd, and the N> syntax can only be used for N from 0
through 9, so there's no way to use the latter to re-redirect a
descriptor created by the former (which are all numbered more than
10).

So you have to do it something like this (example using an anonymous function):

function {
  local zshlog
  : {zshlog}>/dev/null
  somefunc "$@"
  {zshlog}>&-
} ... args for somefunc ...

> This is generally achieved per-statement or for a statement-list.
>
>     >$zshlog command echo foo bar

I presume that should be >&$zshlog




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