1833687 Members
4143 Online
110062 Solutions
New Discussion

strange printf behaviour

 
Uwe Steinhoff
New Member

strange printf behaviour

Under HP-UX B.10.20 running on a 9000/780 machine, the following command gives
strange results:
command:
/usr/bin/printf "%.2d\n" 08
result:
printf: Error converting 08
00

The command
/usr/bin/printf "%.2d\n" 8

runs fine. (result : 08 )
What's wrong ?
1 REPLY 1
Tom Dawes-gamble_2
New Member

Re: strange printf behaviour

The reason is the leading zero causes printf to
atempt to convert from Octal.

/usr/bin/printf "%02d\n" 011

results in a "09" being printed.