Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers

2024-05-29 Thread porterleete
"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  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



Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers

2024-05-29 Thread porterleete
>I guess it could be more explicit

Yes, that is essentially what I was asking for. There are several
standards for printf, and it was ambiguous which one was being
referred to. There's the C standards, the POSIX standards, and the
Single Unix Specifications. I didn't know which one was being referred
to, got confused, and made a weird assumption.

On Mon, May 27, 2024 at 10:09 PM Oğuz  wrote:
>
> POSIX Issue 8 will require that this feature is supported, see 
> https://www.austingroupbugs.net/view.php?id=1592
> Perhaps a future version of Bash will have it.
>
>
> --
> Oğuz
>



Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers

2024-05-27 Thread Oğuz
POSIX Issue 8 will require that this feature is supported, see
https://www.austingroupbugs.net/view.php?id=1592
Perhaps a future version of Bash will have it.


-- 
Oğuz


Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers

2024-05-27 Thread Lawrence Velázquez
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



Re: printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers

2024-05-27 Thread Collin Funk
porterleete  writes:

> 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 '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

Collin



printf %m$ and %*m$ unimplemented in Bash, but implementated in C compilers

2024-05-27 Thread porterleete
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux portercomp3 6.9.1 #1-NixOS SMP PREEMPT_DYNAMIC Fri
May 17 10:18:09 UTC 2024 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 26
Release Status: release

Description:
  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, and therefore do not know where to find more
complete documentation for it.

Repeat-By:
The following program runs without warnings or errors in clang, and in
gcc only warns on -Wpedantic with "warning: ISO C does not support %n$
operand number formats [-Wformat=]":
#include 
int main(void) {
printf("%2$*1$d", 10,100);
return 0;
}

The following line of bash script errors in bash:
`printf '%2$*1$d' 10 100`
Outputting:
bash: printf: `$': invalid format character


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.