From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32125 invoked from network); 19 Oct 2021 19:51:04 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 19 Oct 2021 19:51:04 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1634673064; b=Kj8Cw/zT3+xxTs30H1qE8Uo+ukyYtm4nphrKIn7LImQ+JOQfPg0w9st/wM01yegeAsniWYnXS0 WqD9eTTICDASKQyg5TUtdDmxOANRwYRYWlRrf2oDUli/CzjsrhQ5uDs09/mM+jeMCwC36eEbei Ti8xk6rWTV2rKXOGOT+Jilpk3V3E3dLRJWJJ8VJZM40DnkH1/r+LXr0JJHz3LlRaEiUOGjJf03 hv08mhHWinHzHDOp8aUO69/pKYdl06wYTh9paxEzeOoD77FSC9XU2xGCkyEhJNSEjMaGfsL7qg WhFwRMOMnuPzibnPtY7WqdnYhPKW7ya/+uPZAJOE6NWRDw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f54.google.com) smtp.remote-ip=209.85.128.54; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1634673064; bh=YYTdWbjiGerN7qFXlIxgzec09uCeECW1QTofgYTd6UI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=Hq6fVNU0Etgss6WC+Uqno+ojh1Cmj118JGuBIedPoQl/m6yLwF9hqF7cK5xSxs5XUMqGFGKil+ yX8H3FyNudFoYilbSaejtjhzKniTXen+52mQBo1qXGTlDdDhdKUl5UmMdIyxNU3jwEFSs2YOGQ NL4g0tZsk7NCKfA6h9YGNLLRomnrsll6x6hUFwxYnpncRfD0uSWNBmgHQyWWcf5o5YUP0l9rjb gfMhNp3fTP3R+kGpmnB9zCzGSFLo/xlQt3daWTWs9+mH6wUYsOBkzhmLVy8yhwCDbjLxZs4M+v DytqMl8n3/m418tOo+pKq9/+9Eebt47M48ToEwO1Vn7jPA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=QkGMoPz/PJPryOjFJLoRL1SUCCem0JQFi62wHJGxchg=; b=aazUuJVwEkbDg9luvWEAKKF0lg 9Wbr4XUNVIvAGnIoclvAQ7YS1Y1vmi6my9EVabTG+re6HQAyAK2dy/eRywOef1T/9OIkOguHjB2ID uzMZGqNuu//nwQubpAlpxm9TyG4F1j63vLTZeg9ull8ygVfhT+BjObf+O+YwS5roUbA6xWCdhFlU/ 5lTt/ryQanIZFwtE5fdwM2XiblWBb4JjG23cEy09pHLYIGZ+9fHb0kaQMiH1taBL0XxWs08g7DTaq FWJYUMhlCAFO2lHRJ6Qpm8E6LHJilEd13+u4CeJH9KJHn7O3GoKl6RZSYqBl2e7n6iWjg7Gevx+5B 7k4cuDoQ==; Received: from authenticated user by zero.zsh.org with local id 1mcv8a-0002aw-0g; Tue, 19 Oct 2021 19:51:04 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f54.google.com) smtp.remote-ip=209.85.128.54; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f54.google.com ([209.85.128.54]:36857) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mcv7h-0001ta-Iq; Tue, 19 Oct 2021 19:50:10 +0000 Received: by mail-wm1-f54.google.com with SMTP id z77-20020a1c7e50000000b0030db7b70b6bso5116250wmc.1 for ; Tue, 19 Oct 2021 12:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=QkGMoPz/PJPryOjFJLoRL1SUCCem0JQFi62wHJGxchg=; b=KHdZzdaNkPhoo1oXHQLiOAr0P+veya+DRDiZcnkeDKIApwAxLfJzxZ7YlcpZnLKWAj KPcEdwmfPVJbJG/Kd+QCwxs5/VhU/Nlr6eRDD7rxW12wi9I43c8WSv00rYm76LTCtVRI 2G+D9VIZZKjpszZHHhqLPWeCAM3KWDXDEjwID6efKXZzbf3tjdHGPbcWgmXPIdvH3n+g kuZp5JJYni0qHlCd1AL1GuhCFEm5/QlKsPldtuX+KGym8jJ4o8gbQXN8Av4GzMqVoBUS m0tWz21dt9oAGHfi3nxFVrEACYU1Chtcm+W01kWL+HTYs0rN62y17vAkxcsf/LqMuBLp ztqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=QkGMoPz/PJPryOjFJLoRL1SUCCem0JQFi62wHJGxchg=; b=6xoWLWRtmNOxhayuwYp8eAmwabiQSVwHXQfOvs1iSs1Y8U7mr/GMw/Fj/BrQ69Y7GM T2gwE7rIV1myJ1Lbu+YcW4j6cJcQtP55Sc5ok7++GZy5P+2VXG3A1OZxiVqU5vqDgNXr vu94G89dphubJT0MoWi4C/BLc7mF+HtfGlf2Ydni4YvmArNA917q8/eSA1PGnnsmPwB2 swzQzarf5WNjJR0PVMkJXSnlvUbtAB7X2N+B3AQ8Jkfqv7S7BzIfK0kitHG67CD0dUSn EZgR4BZUsJN8UcqQHvvJ3voCY5zKyzqZ12fhsqzcRbAdBqmI6BRlm7Yr5fZusMDSm9Jz rzRA== X-Gm-Message-State: AOAM53083YkOMgJ5C7O5e/j0A6Ol5c+5Z5aA2iro3SzXxuWz9CHLPeAp ayX2JbUNd58ordwrzKeE7V/wERS7PFy73f7DlmerQ6K3X4LbxA== X-Google-Smtp-Source: ABdhPJwo3YajIsUoODNRCTCtEf1WwbOmqxPp9sNzIcUNgvy/5l0jNIlxbliwQJBs6iFYwThJ56eT7V8+TFRCQ4192fM= X-Received: by 2002:adf:b1d4:: with SMTP id r20mr46452215wra.308.1634673008915; Tue, 19 Oct 2021 12:50:08 -0700 (PDT) MIME-Version: 1.0 From: Zach Riggle Date: Tue, 19 Oct 2021 14:49:57 -0500 Message-ID: Subject: Temporary redirection of named file descriptors To: Zsh Users Content-Type: multipart/alternative; boundary="00000000000005397805ceb9f8bd" X-Seq: 27251 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --00000000000005397805ceb9f8bd Content-Type: text/plain; charset="UTF-8" Hello all! TL;DR: How can I redirect a named file descriptor (to e.g. /dev/null), but only for one statement? Neither of these work, and Section 7 doesn't provide an example. somefunc {myfd}>/dev/null somefunc $myfd>/dev/null == More context and background == I have a neat little library of commonly-used functions, "zshlib", that I've got set up as an autoloadable module (technically an auto-loaded function, but it exposes 50+ functions to the global namespace and I'm more familiar with Python nomenclature). Scripts which use "zshlib" load it at the very top of the script. The first thing thing "zshlib" does is create a named file descriptor: exec {zshlog}>&2 This is done for lots of reasons, mainly the "run a command but print it out and properly escaped so the user knows what is taking so long" functions. The executed command may write to stdout or stderr, and I wanted to ensure my library does not pollute those streams, or prevent them from being grepped / redirected / filtered / etc (as much as possible, anyway). This is generally achieved per-statement or for a statement-list. >$zshlog command echo foo bar This is all great, but occasionally I want to silence the output from "zshlib". I assumed either of these syntaxes would work: somefunc {zshlog}>/dev/null somefunc $zshlog>/dev/null The first fails with "can't clobber parameter zshlog containing file descriptor 11". The second simply uses $zshlog as a parameter to somefunc. --00000000000005397805ceb9f8bd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello all!

TL;DR: How ca= n I redirect a named file descriptor (to e.g. /dev/null), but only for one = statement?
Neither of these work, and Section 7 doesn't provi= de an example.

=C2=A0 =C2=A0 somefunc {myfd}>/d= ev/null
=C2=A0 =C2=A0 somefunc $myfd>/dev/null

<= /div>
=3D=3D More context and background =3D=3D

I have a neat little library of commonly-used functions, "zshlib&quo= t;, that I've got set up as an autoloadable module (technically an auto= -loaded function, but it exposes 50+ functions to the global namespace and = I'm more familiar with Python nomenclature).

S= cripts which use "zshlib" load it at the very top of the script.= =C2=A0 The first thing thing "zshlib" does is create a named file= descriptor:

=C2=A0 =C2=A0 exec {zshlog}>&2=

This is done for lots of reasons, mainly the = "run a command but print it out and properly escaped so the user knows= what is taking so long" functions.=C2=A0 The executed command may wri= te to stdout or stderr, and I wanted to ensure my library does not pollute = those streams, or prevent them from being grepped / redirected / filtered /= etc (as much as possible, anyway).

This is genera= lly achieved per-statement or for a statement-list.

=C2=A0 =C2=A0 >$zshlog command echo=C2=A0foo bar

<= div>This is all great, but occasionally=C2=A0I want to silence the output f= rom "zshlib".=C2=A0 I assumed either of these syntaxes would work= :

=C2=A0 =C2=A0 somefunc {zshlog}>/dev/null
=C2=A0 =C2=A0 somefunc $zshlog>/dev/null

The first fails with "can't clobber parameter zshlog=C2=A0contain= ing file descriptor 11".
The second simply uses $zshlog as a= parameter to somefunc.

--00000000000005397805ceb9f8bd--