bug-bash
[Top][All Lists]
Advanced

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

Re: Incorrect option processing in builtin printf(1)


From: Chet Ramey
Subject: Re: Incorrect option processing in builtin printf(1)
Date: Mon, 22 Jul 2019 16:16:55 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 7/22/19 1:56 PM, address@hidden wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: netbsd
> Compiler: gcc
> Compilation CFLAGS: -O2 -D_FORTIFY_SOURCE=2 -I/usr/include -Wno-parentheses 
> -Wno-format-security
> uname output: NetBSD jinx.noi.kre.to 8.99.30 NetBSD 8.99.30 (1.1-20190114) 
> #9: Mon Jan 14 13:29:08 ICT 2019  
> address@hidden:/usr/obj/testing/kernels/amd64/JINX amd64
> Machine Type: x86_64--netbsd
> 
> Bash Version: 5.0
> Patch Level: 7
> Release Status: release
> 
> Description:
>       POSIX specifies that printf(1) has no options, and by not
>       specifying that it is intended to comply with XBD 12.2 effectivly
>       says that it is not.   That is, in printf, the first arg is
>       always the format string, whatever it contains.
> 
>       So
>               printf ---              should print three - chars to stdout
>               printf -%d 3            should print -3 to stdout
>       those do not work in bash (nor do any similar cases), even when bash
>       is in posix mode.

No. POSIX allows additional options as extensions, even when the syntax
description OPTIONS section says "None." ("need not" is not the same as
"must not").

Conforming applications are required to use `--' before any operands that
begin with a dash:

"The requirement for recognizing "--" is because conforming applications
need a way to shield their operands from any arbitrary options that the
implementation may provide as an extension. For example, if the standard
utility foo is listed as taking no options, and the application needed to
give it a pathname with a leading <hyphen-minus>, it could safely do it as:

foo -- -myfile

and avoid any problems with -m used as an extension."

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tag_17_04

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

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