[Top][All Lists]

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

About printf %2$s (Was: Coordination on standardizing gettext() in futur

From: Stephane Chazelas
Subject: About printf %2$s (Was: Coordination on standardizing gettext() in future POSIX)
Date: Fri, 31 Jan 2020 21:26:33 +0000
User-agent: NeoMutt/20180716

2020-01-24 15:14:48 +0100, Joerg Schilling:
> > >   printf "$(gettext 'Hello World %2$d %1$d')\\n"  1 2
> > > 
> > > to be able to control the order of the output of arguments in a way that 
> > > is 
> > > specific to the target language. ...
> >
> > > BTW: this extension is also available in /bin/printf on OpenSolaris and 
> > > FreeBSD.
> Most platforms support it anyway. It has been introduced in 1988 for ksh88 
> and 
> /bin/printf on SVr4/Solaris - but only usable for string parameters as:
>       printf "Hello World %2$s %1$s\\n"  1 2
> mksh          a ksh88 clone

ksh88 had no printf builtin.

You might have been mislead by Solaris' /usr/xpg4/bin/sh

On Solaris 11,

$ /usr/xpg4/bin/sh -c 'type printf'
printf is a shell builtin


$ truss -ft execve /usr/xpg4/bin/sh -c 'printf "x"'
1382:   execve("/usr/xpg4/bin/sh", 0x7FEF43B27CC8, 0x7FEF43B27CE8)  argc = 3
1383:   execve("/usr/bin/getconf", 0x7FEF43B27A70, 0x7FEF43B27CE8)  argc = 2
1382:   execve("/usr/bin/printf", 0xFA6897198, 0xFA68971E0)  argc = 2

No idea what that undocumented "builtin" does other than invoking
the standalone printf utility (still looked up in $PATH)

mksh has no printf builtin either

AFAIK, the printf utility is a POSIX invention (ksh93 release
notes do mention the POSIX origin), possibly inspired by
research Unix 10th edition which had a printf utility (but not
%b for instance) possibly from as far back as
1986 (if we're to beleive the timestamp of printf.c at
$ tar tvf v10src.tar.bz2 cmd/printf.c
-rw-rw-r-- root/root      3621 1986-07-29 20:40 cmd/printf.c

The Debian build of mksh (maintained by the maintainer of mksh)
also generates a lksh executable which includes a printf builtin
but that builtin doesn't support %2$s and I beleive is derived
from code of the standalone printf utility in mirOS (based on

mksh is derived from pdksh. pdksh (itself based on the Forsyth
shell, another clone of SysV sh) was intended as a limited
clone of ksh88, but mksh has incorporated features of ksh93, zsh
and bash and some of its own (some of which copied by bash)

I don't know where the %2$x format in printf(3) comes from.


reply via email to

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