[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Where is the usage of '.' in printf documented?
From: |
Eric Blake |
Subject: |
Re: [Help-bash] Where is the usage of '.' in printf documented? |
Date: |
Fri, 20 Mar 2015 08:38:53 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
On 03/20/2015 06:15 AM, Greg Wooledge wrote:
> On Thu, Mar 19, 2015 at 03:56:43PM -0500, Peng Yu wrote:
>> printf "%0.s-" {1..10}
>
> I hate ugly hacks like this. Truly, I do.
Concur.
>
> What that bit of code says, in human-readable form, is "For every argument
> after the format, I want you to print the argument truncated to length
> zero, and then a hyphen." Or in simpler terms, "print this many hyphens
> in a row in a really twisted way".
Rather, "For every argument after the format, I want you to print
0-padded strings truncated to length zero, and then a hyphen", except
that 0-padded strings are not defined by the C standard.
>
> For some reason, the code you found has replaced the slightly more
> readable %0.0s with %0.s (and you could also use %.s for the same result,
> dropping both zeroes). I'd at least stick with %0.0s because I find
> that the least unclear of the various forms.
I wouldn't. %0.0s is undefined, while the shorter %.0s and %.s are
well-defined (even if arcane).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature