Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.bugs.dist > #1011759 > unrolled thread

Bug#961740: printf attempts to parse options and fails to print --help

Started byMelvin Vermeeren <vermeeren@vermwa.re>
First post2020-05-28 17:30 +0200
Last post2020-05-29 20:20 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.debian.bugs.dist


Contents

  Bug#961740: printf attempts to parse options and fails to print --help Melvin Vermeeren <vermeeren@vermwa.re> - 2020-05-28 17:30 +0200
    Bug#961740: printf attempts to parse options and fails to print --help Michael Stone <mstone@debian.org> - 2020-05-28 18:20 +0200
    Bug#961740: printf attempts to parse options and fails to print --help Jakub Wilk <jwilk@jwilk.net> - 2020-05-29 19:40 +0200
      Bug#961740: printf attempts to parse options and fails to print --help Melvin Vermeeren <vermeeren@vermwa.re> - 2020-05-29 20:20 +0200

#1011759 — Bug#961740: printf attempts to parse options and fails to print --help

FromMelvin Vermeeren <vermeeren@vermwa.re>
Date2020-05-28 17:30 +0200
SubjectBug#961740: printf attempts to parse options and fails to print --help
Message-ID<AbsDM-5yg-11@gated-at.bofh.it>

[Multipart message — attachments visible in raw view] — view raw

Package: coreutils
Version: 8.30-3

Hi,

POSIX specifies printf has no options, meaning this should print "--help". 
Arguments parsing must simply not be attempted at all in order to be compliant 
as far as I know.

$ /usr/bin/printf --help
Usage: /usr/bin/printf FORMAT [ARGUMENT]...
  or:  /usr/bin/printf OPTION

  ...

From https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html:
> SYNOPSIS
>
>    printf format [argument...]
>
> ...
>
> OPTIONS
>
>    None.

Bash also does not handle this correctly. However bash is not POSIX sh, hence 
it is not a bug. (It appears bash some some "printf -v var" extension.) I also 
tested zsh, which appears to be fully compliant.

Thanks,

-- 
Melvin Vermeeren

[toc] | [next] | [standalone]


#1011766

FromMichael Stone <mstone@debian.org>
Date2020-05-28 18:20 +0200
Message-ID<Abtq9-64u-5@gated-at.bofh.it>
In reply to#1011759
On Thu, May 28, 2020 at 05:56:09PM +0200, Melvin Vermeeren wrote:
>On Thursday, 28 May 2020 17:50:20 CEST Michael Stone wrote:
>> Yes, running printf with the single argument --help will print help. A
>> portable and posix-compliant alternative would be to run "printf '%s'
>> --help". This is extremely unlikely to change.
>
>This is not the only problem that occurs, printing -- does not work either.

same solution will work!

>Coreutils should aim for POSIX compliancy, perhaps it would be better if I
>take this bug upstream?

You certainly can, but they will probably also consider this to be of 
purely academic interest. The solution I provided above is the only 
portable way to make what you're trying to do work, regardless of POSIX. 
Even if I changed the debian package today, you'd have to continue to do 
the above basically forever because of the enormous installed base of 
implementations don't work the way you're requesting. And not having the 
help output will likely confuse more people who won't know why it 
wouldn't work.

[toc] | [prev] | [next] | [standalone]


#1011913

FromJakub Wilk <jwilk@jwilk.net>
Date2020-05-29 19:40 +0200
Message-ID<AbR98-3om-11@gated-at.bofh.it>
In reply to#1011759
* Melvin Vermeeren <vermeeren@vermwa.re>, 2020-05-28, 17:17:
>POSIX specifies printf has no options, meaning this should print "--help".
>Arguments parsing must simply not be attempted at all in order to be 
>compliant as far as I know.
>
>$ /usr/bin/printf --help
>Usage: /usr/bin/printf FORMAT [ARGUMENT]...
>  or:  /usr/bin/printf OPTION

I think you're misinterpreting the standard. If it really meant that 
implementations must not support any options, it would say so 
explicitly, like it does for echo:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html

-- 
Jakub Wilk

[toc] | [prev] | [next] | [standalone]


#1011918

FromMelvin Vermeeren <vermeeren@vermwa.re>
Date2020-05-29 20:20 +0200
Message-ID<AbRLP-3Qo-1@gated-at.bofh.it>
In reply to#1011913

[Multipart message — attachments visible in raw view] — view raw

On Friday, 29 May 2020 19:35:06 CEST Jakub Wilk wrote:
> I think you're misinterpreting the standard. If it really meant that
> implementations must not support any options, it would say so
> explicitly, like it does for echo:
> 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html

Indeed, you are correct. In that case printf may have >= 0 options and whether 
options are parsed at all is unspecified. This also explains the lack of any 
reference to "Section 12.2, Utility Syntax Guidelines".

Apologies for the noise.

-- 
Melvin Vermeeren

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.bugs.dist


csiph-web