Technical article 105604

/usr/bin/printf does not seem to print variables with leading zeroes.

OpenServer 5.0.0OpenServer 5.0.2

Written · Last revised

Problem

Under UnixWare, if I use the command:

# printf "%s " 09
it correctly returns:
# 09
However if I use the command:
# printf "%d " 09
I get the error message:
# UX: printf: WARNING: "09" expected numeric value

and then it does print the 0, but it never prints the 9.

Similarly, under SCO OpenServer, the same command returns the error message:

# printf: "09": not completely converted

and then it does print the 0, but fails to print the 9.

Why can't printf print variables with leading 0's?

Cause

As in the printf function from the C language:

# /usr/bin/printf "%d " 09
expects an OCTAL value.

As such, values such as 01, 02, 03, 04, 05, 06, 07 will be printed accordingly, but values such as 08 and 09 are not valid. Hence /usr/bin/printf's behavior in this instance is the normal behavior, although the error message that results is somewhat cryptic.

Solution

The obscurity of the error message has been reported to SCO Engineering.

See also

printf(C)

From the Xinuos technical article database, record 105604. Reproduced with permission. The original is at www.sco.com/ta/105604, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.