From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23648-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 1df76219 for ; Mon, 17 Sep 2018 20:55:27 +0000 (UTC) Received: (qmail 4558 invoked by alias); 17 Sep 2018 20:55:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23648 Received: (qmail 4731 invoked by uid 1010); 17 Sep 2018 20:55:12 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(-2.6/5.0):. Processed in 6.440125 secs); 17 Sep 2018 20:55:12 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=8dWdqp iZfB6x8dkSd9mjE9/PjGffCIjrg8xN9P06F9g=; b=DLGvIXpID2GKDLZOsBELp6 EsKBbmUP4HPinZdyjbpW3zp/mDeltLpEIXLBEEhU8upiT8WND4HqI9sVMA6KA0Ue ywR7I0xxwCgdtpBHsVg0M/YwwRfX4QhdLiKjk5mA9hjewHMbY9H8M4bu+cnHYOwS qN5M266NkUOsxYB972sIAPK5+FM2zdnPof/zlQZAGN3zkwIbPUesagxISSan06kG eGztn3T2cdKDPjml+vqolmd1j4G4E2wuabJZA9JJ8pdir1N08NOA6XMmFy1tSsEr crsA6XR+ih/4XyHMA1ja+CEqxaiGuzJSCEvvnxwuyoN+JZKfZZbq/1WCBG1dGSVw == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=8dWdqp iZfB6x8dkSd9mjE9/PjGffCIjrg8xN9P06F9g=; b=vHpgR4HH1uhrNg0LmqH2Ex BRjG7zx5HJOn1Pg/Ss9INoBg+BLzfmkpcATyw2IawcrABfUbyIhAvo/X2p9mkcNa SQRieiZ23GQHH3qkOmuV3hYHKcGzjT8QrcM/zhP3CGz4RPCtJ3dihKFoLta2Gcg+ qg/mw+998vVzzGbbTmBArEPUd5XmjWhLlu8i8206cT9atjFx+xRzA2sphtTWoHjS OmlMW9jTyLHER3HfvivR0TiW/eIueTJDhnSffqmGQlWEg2VQ+OVDh73Il0HE5J9U igZgAaWw1UpuBEiqYJdfYTdR+GcAEpMwiINOqX6wYIjYIOosIDCSxxW+4np/12fA == X-ME-Proxy: X-ME-Sender: Message-Id: <1537217203.28092.1511309952.71C4C11C@webmail.messagingengine.com> From: Daniel Shahaf To: Ben Klein , zsh-users@zsh.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-e556cd15 Date: Mon, 17 Sep 2018 20:46:43 +0000 In-Reply-To: References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <20180903140214.76kbzgpfru6atc5u@tarpaulin.shahaf.local2> <20180903184353.yzujt7ywnlvufeye@gmail.com> Subject: Re: Capturing STDOUT without subshells or file I/O Ben Klein wrote on Mon, 17 Sep 2018 16:13 -0400: > So I guess the question is up again, how should I capture the `printf` > output without the `-v` option, no subshells, and no file I/O? Is there > a different method for ZSH v5.1? > > I would like to do `printf '%.2f' "3.4" | read var` but it appears that > the command before the pipe causes a subshell to be opened. > If you could call pipe(2), you'd be able to do . printf foo >&$w read bar <&$r . without forking (where $r,$w were returned by pipe(2)). However, I don't see any suitable callsite in the 5.6 codebase. (Don't have 5.1 handy, sorry.) Maybe we should expose pipe(2) in zsh/system? > Or potentially, is there some way I can make a wrapper that will use > `printf -v` when available, but falls back to another method? Should be possible, yes. You can tell the two cases apart by doing: if printf -v >/dev/null ; then Cheers, Daniel