bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf and the $ modifier


From: Eric Blake
Subject: Re: printf and the $ modifier
Date: Fri, 19 Dec 2014 08:14:04 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 12/19/2014 07:46 AM, Maarten Billemont wrote:

> Is there a particular reason why bash's built-in printf does not support
> this format modifier?

Because POSIX does not require it to.  printf(1) is only required to
have a subset of printf(3) functionality:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html#tag_05

That subset does not include $ reordering.

>  Does bash re-implement printf or does it use the
> Standard C Library's printf?  (If the former; why?)

A combination - it MUST parse the string itself (because POSIX requires
printf(1) to understand %b, but %b is not part of printf(3)), but then
calls into the system's printf family as appropriate.  And you'd be
shocked at how many libc have bugs of one form or another in their
printf(3) (even glibc's printf could cause a core dump when using %A on
certain long double bit values, until earlier this year).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]