Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf \045 (or whatever the character code for % is)



On Wed, 29 Dec 2010 22:11:55 +0100
Jilles Tjoelker <jilles@xxxxxxxx> wrote:
> While trying to run the FreeBSD sh testsuite with zsh, various tests
> fail because the printf builtin interprets \045 (ASCII) as a percent
> sign introducing a format specification instead of a literal percent
> sign. The \045 arises because I create all 255 non-zero byte values via
> octal escapes.
> 
> POSIX's description assumes that the backslash escapes and format
> specifications are processed in one pass and simply says that an octal
> escape sequence shall write the corresponding byte. If they are separate
> passes the backslash escape removal step needs to know about percent
> signs.

That's a reasonable assumption, but the function handling print is an
appalling mess so it's not easy to fix without a major rewrite.  The
code for printf doesn't really have any business being associated with
the code for print, they're there for different purposes entirely based
on completely different specifications.  At the moment printf does the
same as 'print -f', so it has all the same oddities as print whether it
should or not.  (In my opinion, anyone deliberately asking for combined
print and printf behaviour deserves everything they get so I'm perfectly
happy to let 'print -f' fester while standardising printf.)  However, I
never get volunteers for tidying the shell up, so we're probably stuck
until someone gets fed up enough to look into it.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author