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 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 %Much nicer, wow. Looks like I'll be revising quite a few of my scripts today.