[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C co
From: |
porterleete |
Subject: |
Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers |
Date: |
Wed, 29 May 2024 02:54:04 -0500 |
"The 'printf' in shells is different than the 'printf' specified by ISO
C/POSIX. The documentation for the bash built-in can be found here:
$ info '(bash)Bash Builtins'
The 'printf' provided in your C library should be found in man page
section 3. Your system probably comes with a program (not a shell
built-in) too. That can be found in man page section 1.
# C library.
$ man -s 3 printf
# System program.
$ man -s 1 printf"
Is ambiguous and confusing documentation not considered a bug to be
fixed? Please say as much in the documentation, then.
On Mon, May 27, 2024 at 8:23 PM Lawrence Velázquez <vq@larryv.me> wrote:
>
> On Mon, May 27, 2024, at 8:58 PM, porterleete wrote:
> > The man page for printf says that for integer m, %m$ lets you
> > specify which argument that the conversion specification will use.
> > Similarly, using *m$ instead of * in a conversion specification lets
> > you specify which argument the * will pull from. This feature is
> > unimplemented in Bash. I am guessing that Bash is using either the ISO
> > C standard, or an older version of some mainstream compiler for printf
> > or some other standard
>
> Neither. Bash's printf is based on the POSIX printf utility:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
>
> It also implements a few extensions, which are documented in the
> bash man page and manual. (IIRC there is also at least one
> undocumented extension.)
>
>
> > Fix:
> > Either update the documentation of what printf in bash actually does.
> > If printf is using a standard for printf other than "what the biggest
> > C compilers currently do", document which standard it's using or
> > update it to the newest standard used by gcc and clang. If it really
> > is just this one feature that's missing, add it in or document its
> > absence.
>
> The bash man page and manual already state:
>
> In addition to the standard printf(1) format specifications,
> printf interprets the following extensions:
> %b [...]
> %q [...]
> %Q [...]
> %(datefmt)T [...]
>
> I guess it could be more explicit, but "the standard printf(1)
> format specifications" refers to the POSIX standard for the printf
> *utility*. The C printf *function* is tangentially related but
> not directly relevant.
>
> --
> vq