bug-coreutils
[Top][All Lists]
Advanced

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

bug#73068: printf: please implement POSIX:2024 argument reordering


From: Bruno Haible
Subject: bug#73068: printf: please implement POSIX:2024 argument reordering
Date: Fri, 06 Sep 2024 16:06:34 +0200

Hi,

POSIX:2024 specifies that printf(1) should support numbered conversion
specifications:
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/printf.html
https://austingroupbugs.net/view.php?id=1592

Could this support please be added to GNU coreutils? As of coreutils 9.5,
I still get:

  $ /usr/bin/printf 'abc%2$sdef%1$sxxx\n' 1 2
  abc/usr/bin/printf: %2$: invalid conversion specification

Rationale: It was pointed out in https://austingroupbugs.net/view.php?id=1592
that these four statements do all the same thing:

1) pid=$$; eval_gettext "Running as process number \$pid."; echo
2) printf_gettext "Running as process number %d." $$; echo
3) printf "`gettext 'Running as process number %d.'`" $$; echo
4) printf $(gettext 'Running as process number %d.') $$; echo

The first one has the drawback that it requires the programmer to
add backslashes to their format strings.

The second one has the drawback that it requires a 'printf_gettext'
program (that does not yet exist).

The third and fourth one (suggested by Jörg Schilling, IIRC) feel more
natural to a shell script programmer. However, they require that
printf supports numbered arguments. In the first time, we would use
a shorthand
  $printf
where (on most GNU systems) printf='/usr/bin/printf', until bash, dash,
etc. support it as well.

The long-term goal is to be able to change the GNU gettext documentation
https://www.gnu.org/software/gettext/manual/html_node/sh.html
to list:
  "
   Formatting with positions
     printf
  "

Bruno








reply via email to

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