From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23647-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=-0.9 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID 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 3442475f for ; Mon, 17 Sep 2018 20:13:49 +0000 (UTC) Received: (qmail 14601 invoked by alias); 17 Sep 2018 20:13:34 -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: 23647 Received: (qmail 5872 invoked by uid 1010); 17 Sep 2018 20:13:34 -0000 X-Qmail-Scanner-Diagnostics: from mail-yw1-f50.google.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(209.85.161.50):SA:0(-1.9/5.0):. Processed in 2.988851 secs); 17 Sep 2018 20:13:34 -0000 X-Envelope-From: robobenklein@gmail.com X-Qmail-Scanner-Mime-Attachments: |signature.asc| X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to; bh=rJ3/1Zps3Cuv3Ukuap9XoiPpB0JAftzFTB8BpJ+iBMg=; b=fKkIW6ITGeFnDTmA3QRkDz1T49NSJW0lzA0JvN6AWrlji2MgsDBngCX6rmXvka0aOY M8hCJeTufFz9Pq49JHLLlp8CtyR+5F7a2ztlQLI+xzPAYop/OZ/zjK2M9MP0RJoKPm5y 6oEBGHZA+Du3gSlA2l9L79MQsLFGvH6Ol8fBVWlcRI6gtAZoIAIx4Y6Evdu1/wjj5J3G z9nZuzZjf8Bg2gNRtGPlOZTwkfJirRCHkRaCJXPtMAfqqKNqPw/gmdpK4DYdCT+gvh+6 NnLxO5JW1ns5HfBNmoY6Gvd7F9NNCwcgsxi/dHXKqb8ltoPUWK8TcTlpvcN77Eh+z+OH fNQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to; bh=rJ3/1Zps3Cuv3Ukuap9XoiPpB0JAftzFTB8BpJ+iBMg=; b=l/MITHfCvL7pSybOJ++uXyQqJX9GOOc5JGm9i1Ys9mR3rGdEbrljwnhQ9G6e71fL8L y+Z6ENtJt3t9b+lyOinEIevwziKUb3MJVNOHp9Dqm6JqlREUWkjfEhexEka8OBqRf6IB oFGWlsWN5mFy8zg4CN8xwovOWUUiOkWb4046rZ5kL2J89JGXEC13OUfLhVKU/VbuNUPw B+GZ03QuXtD3wITF3ODCetVwDJmz3LBCT6kwnPgUf2Vj82oVNkr+jpnIhyTo+QFmJSQs OmXf5n6l+Od4xnNHexOibjc8omNBnm74rDkafEdR6dtQqoyFjjkjFQcuFEC8uiQ8FWfi Bb7Q== X-Gm-Message-State: APzg51DqN4J1nomDDZuUu5qLiikODCpculj/C7a896aVZjfMZSEVaYxv JFiCOsnVhhJmV+HS3cAC/X8= X-Google-Smtp-Source: ANB0VdaMgDdDXyCj33ZVo3Drd4r30SA5FQ4DnZeeK9EXewxTNDZEvN8eY6bPghDY1ig6Cu/6OMnaug== X-Received: by 2002:a81:578e:: with SMTP id l136-v6mr10947015ywb.396.1537215207562; Mon, 17 Sep 2018 13:13:27 -0700 (PDT) Subject: Re: Capturing STDOUT without subshells or file I/O To: zsh-users@zsh.org References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <20180903140214.76kbzgpfru6atc5u@tarpaulin.shahaf.local2> <20180903184353.yzujt7ywnlvufeye@gmail.com> Cc: Daniel Shahaf , Joey Pabalinas From: Ben Klein Openpgp: preference=signencrypt Autocrypt: addr=robobenklein@gmail.com; prefer-encrypt=mutual; keydata= mDMEW4xlWhYJKwYBBAHaRw8BAQdAc4bu9FvZW7KVI/XTSNArUywJnJ6rspqokOlLmdYHpEy0 IkJlbiBLbGVpbiA8cm9ib2JlbmtsZWluQGdtYWlsLmNvbT6IlgQTFggAPhYhBOHTD5LgKr+B 0cEun4EyYIP3o2JVBQJbjGVaAhsDBQkDwmcABQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJ EIEyYIP3o2JVSGYA/iwjCP86SP80hezhBqn31x2tsOvQRDb0aqYC3rcv2ZafAQC9VQxIe4Tr 3L40INqNo/cl7eUWfiRegwBTeYtcya4zBbg4BFuMZVoSCisGAQQBl1UBBQEBB0DXVfLX5XuW 05wiu+s6XHUE3iF5sJCQW2wrT+MOnOopSwMBCAeIfgQYFggAJhYhBOHTD5LgKr+B0cEun4Ey YIP3o2JVBQJbjGVaAhsMBQkDwmcAAAoJEIEyYIP3o2JV0UoBAJhQNH1i2+Rm//o2GBIoUA7c ywHlC/257mLtJPPnLJo4AP9csP4/Aw8RX7TlCU5X+mmmI1kligdWaAb+mNpy40MsAg== Message-ID: Date: Mon, 17 Sep 2018 16:13:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180903184353.yzujt7ywnlvufeye@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TCfYdptk7fGUIrvnexazAudN9VrFnawji" --TCfYdptk7fGUIrvnexazAudN9VrFnawji Content-Type: multipart/mixed; boundary="reffxbkaQ6xHtIfW0RE1ZR65PWBrbqhHO"; protected-headers="v1" From: Ben Klein To: zsh-users@zsh.org Cc: Daniel Shahaf , Joey Pabalinas Message-ID: Subject: Re: Capturing STDOUT without subshells or file I/O References: <04a12c6a-c926-b088-f386-8a2bdb81dad2@gmail.com> <20180903140214.76kbzgpfru6atc5u@tarpaulin.shahaf.local2> <20180903184353.yzujt7ywnlvufeye@gmail.com> In-Reply-To: <20180903184353.yzujt7ywnlvufeye@gmail.com> --reffxbkaQ6xHtIfW0RE1ZR65PWBrbqhHO Content-Type: multipart/alternative; boundary="------------E8E624139BC4A29C77111293" Content-Language: en-US This is a multi-part message in MIME format. --------------E8E624139BC4A29C77111293 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable So I just rewrote a large portion of a codebase on being able to use `printf -v`, but it looks like this support was added after ZSH 5.1, which I intend to support. (Ubuntu 16.04 still has it.) 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. Or potentially, is there some way I can make a wrapper that will use `printf -v` when available, but falls back to another method? On 09/03/2018 02:43 PM, Joey Pabalinas wrote: > On Mon, Sep 03, 2018 at 02:02:14PM +0000, Daniel Shahaf wrote: >> Just pass -v to the builtin printf, e.g., >> >> % printf -v foo 'a%03d' 42 >> % typeset -p foo >> a042 >> %=20 > Much nicer, wow. Looks like I'll be revising quite a few of my scripts > today. > --=20 *\Ben Klein* Founder and Owner of Robosane, robobenklein@robosane.net You can find me elsewhere online as 'robobenklein'. If you need to contact me securely, I am also reachable via GPG, or on Keybase. --------------E8E624139BC4A29C77111293 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

So I just rewrote a large portion of a codebase on being able to use `printf -v`, but it looks like this support was added after ZSH 5.1, which I intend to support. (Ubuntu 16.04 still has it.)

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.

Or potentially, is there some way I can make a wrapper that will use `printf -v` when available, but falls back to another method?


On 09/03/2018 02:43 PM, Joey Pabalinas= wrote:
On Mon, Sep 03, 2018 at 02:02:14PM +0000, Daniel Sha=
haf wrote:
Just pass -v to the builtin printf, e.g.,

% printf -v foo 'a%03d' 42
% typeset -p foo
a042
%=20
Much nicer, wow. Looks like I'll be revising quite a few of my scripts
today.


--
\Ben Klein
Founder and Owner of Robosane, robobenklein@robosane.net=
You can find me elsewhere online as 'robobenklein'.
If you need to contact me securely, I am also reachable via GPG, or on Keybase.
--------------E8E624139BC4A29C77111293-- --reffxbkaQ6xHtIfW0RE1ZR65PWBrbqhHO-- --TCfYdptk7fGUIrvnexazAudN9VrFnawji Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQTh0w+S4Cq/gdHBLp+BMmCD96NiVQUCW6AK5QAKCRCBMmCD96Ni VUXBAQDx48dqbuVJjb1TnsP2AF2CIUhZscuursIoPKd1hYhMZQEA0mwJUHookwTO eyum6UY2Gel/KGmemJa9bUvisLOI+QE= =vg/Q -----END PGP SIGNATURE----- --TCfYdptk7fGUIrvnexazAudN9VrFnawji--