[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf %n is not documented
From: |
Chet Ramey |
Subject: |
Re: printf %n is not documented |
Date: |
Tue, 27 Dec 2022 15:44:29 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 |
On 12/23/22 8:12 PM, Emanuele Torre wrote:
Furthermore, both dash's printf, and the GNU coreutils' printf do not
support %n:
bash-5.1$ dash -c 'printf "$@"' dash %n a
dash: 1: printf: %n: invalid directive
bash-5.1$ /bin/printf %n a
/bin/printf: %n: invalid conversion specification
I am pretty sure %n in printf(1) is an extension. Is it not?
Well, let's see. It looks like I added it in 2001 for ksh93 compatibility,
back when we were still trying to get things added to POSIX. bash, ksh93,
and zsh are the shells that implement (I'm surprised mksh does not), but
since it never made it into the POSIX printf utility, the ash descendents
and yash don't.
ksh93 and zsh both describe the format in terms of what ANSI C specifies,
instead of printf(1), and list the valid format specifiers from ANSI C
they accept. Neither one elaborates on any of the (string) arguments for
the specifiers, since everything is a string argument. If you say there's a
%n specifier, the only thing that makes sense as an argument is a shell
variable name.
So maybe the better thing to do is to list the set of valid format
specifiers from the standard printf(3) set.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/