[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] About printf "%d\n" with no arguments.
From: |
Eric Blake |
Subject: |
Re: [Help-bash] About printf "%d\n" with no arguments. |
Date: |
Tue, 16 Jul 2013 20:34:00 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 |
On 07/16/2013 08:04 PM, Peng Yu wrote:
> Hi,
>
> The following command will print "0". But I think the appropriate
> output should be nothing. As mentioned in the man page "Write the
> formatted arguments to the standard output under the control of the
> format", since there are no arguments, nothing should be printed. Is
> there a way to configure printf to do what I just described? Thanks.
>
> ~$ printf "%d\n"
> 0
POSIX requires this behavior:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
"9. The format operand shall be reused as often as necessary to satisfy
the argument operands. Any extra c or s conversion specifiers shall be
evaluated as if a null string argument were supplied; other extra
conversion specifications shall be evaluated as if a zero argument were
supplied. If the format operand contains no conversion specifications
and argument operands are present, the results are unspecified."
And ksh and dash agree. Sorry, but even if this behavior is not what
you desire, it is intentional in order to comply with POSIX.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature