Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Capturing STDOUT without subshells or file I/O
- X-seq: zsh-users 23648
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Ben Klein <robobenklein@xxxxxxxxx>, zsh-users@xxxxxxx
- Subject: Re: Capturing STDOUT without subshells or file I/O
- Date: Mon, 17 Sep 2018 20:46:43 +0000
- 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 ==
- In-reply-to: <cd8bc7e0-7ae1-8c94-8dea-9b529b2a8fb2@gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <20180903140214.76kbzgpfru6atc5u@tarpaulin.shahaf.local2> <20180903184353.yzujt7ywnlvufeye@gmail.com> <cd8bc7e0-7ae1-8c94-8dea-9b529b2a8fb2@gmail.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author