Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:subject:message-id:mail-followup-to:references
         :mime-version:content-type:content-disposition
         :content-transfer-encoding:in-reply-to:user-agent;
        bh=doIarPLbDrgN9jpEnVLunhcU6X9REgMI030dwKVcXJc=;
        b=DMWpUaDkJWIuebmN8rjy/pLaJpOVfMHS9LODkEtWCFytpEJrKIFihJ8nTAnE0Q2Zmj
         YNpjQgARqeMuvyLa0oIx05n0jrRfRSkq6kWjtVX+ZYT/ScWT2KlxixcAorCr7X7fxB3w
         wb/D6prlc4DlvKE2I5GA1Ja8AlmHHuFAlsGYGOXkW58M4NefDlm8k+1Uvzr+DVWzIf6i
         lJOrdTmnQCuyYXu8sRHqO0Jj+MW0SNVlt2y7UvEDA8ZW8j6h6yl/1YNUoKb9Rb8mKGbX
         NwecvKiT9JJZ7N5+AAKbt3DbmyEel5cI3qlimFsfLrg1T41SPmPQsJubSnIrDFO9T9yX
         HHPg==
X-Received: by 10.28.184.76 with SMTP id i73mr73884586wmf.43.1451673918492;
        Fri, 01 Jan 2016 10:45:18 -0800 (PST)
Date: Fri, 1 Jan 2016 18:45:16 +0000
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: "Starms, William Albert (MU-Student)" <williamstarms@mail.missouri.edu>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Printf builtin missing v flag support
Message-ID: <20160101184516.GB8456@chaz.gmail.com>
Mail-Followup-To: "Starms, William Albert (MU-Student)" <williamstarms@mail.missouri.edu>,
	"zsh-workers@zsh.org" <zsh-workers@zsh.org>
References: <etPan.5684d3d1.74f2df6b.31ec@Ganymede>
 <etPan.5684d62f.51cb8f6f.31ec@Ganymede>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <etPan.5684d62f.51cb8f6f.31ec@Ganymede>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-Seq: zsh-workers 37471

2015-12-31 07:16:00 +0000, Starms, William Albert (MU-Student):
> I had a script malfunctioning on me and printing “-v” to
> stdout, and I found that it’s because zsh (version 5.2)
> doesn’t seem to support the v flag that bash has. I did some
> digging through GNU's bash source and it seems to have been
> added somewhere between 3.0 and 3.1. According to the bash
> documentation:
> 
> printf: printf [-v var] format [arguments]
[...]

Yes, that's a bash-specific feature.

See also ksh93 where:

var=$(printf format arg)

doesn't involve a fork nor pipe (but still trims the trailing
newline characters)

ksh93 tries to only fork to execute external commands. For
builtins when used in command substitutions, ksh93 just adds
their output to the substituted value without actually going
through the whole actual printing through a pipe and reading at
the other end.

That avoids having to add a -v for every builtin command.

$(...) still creates a subshell environment though.

-- 
Stephane

