zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zach Riggle <zachriggle@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Temporary redirection of named file descriptors
Date: Wed, 20 Oct 2021 10:36:00 -0700	[thread overview]
Message-ID: <CAH+w=7ZtC3CtNGwEAsErm9JOHmMgAw-FHW1TmuwLhq2AA9tukg@mail.gmail.com> (raw)
In-Reply-To: <CAMP9c5nFP08KRUmuMRgVzKySNqF0nc-aT37WSBC-SSNDhm3nKQ@mail.gmail.com>

On Tue, Oct 19, 2021 at 12:50 PM Zach Riggle <zachriggle@gmail.com> 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


  reply	other threads:[~2021-10-20 17:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 19:49 Zach Riggle
2021-10-20 17:36 ` Bart Schaefer [this message]
2021-10-20 17:38   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7ZtC3CtNGwEAsErm9JOHmMgAw-FHW1TmuwLhq2AA9tukg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zachriggle@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).