[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] About printf "%d\n" with no arguments.
From: |
Dan Douglas |
Subject: |
Re: [Help-bash] About printf "%d\n" with no arguments. |
Date: |
Wed, 17 Jul 2013 01:16:26 -0500 |
User-agent: |
KMail/4.10.5 (Linux/3.10.1-pf+; KDE/4.10.5; x86_64; ; ) |
On Tuesday, July 16, 2013 08:34:00 PM Eric Blake wrote:
> 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.
>
It might be noted that there are exceptions in non-POSIX extensions. Bash 4.3
and ksh give a non-empty implicit value to '%()T' arguments, and ksh93 and zsh
(and mksh's corresponding feature) omit the implicit null argument for '%q',
which as I've mentioned previously is probably the better behavior.
--
Dan Douglas