printf bad ?

Peter plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org
Fri Mar 18 20:14:33 UTC 2005


Hi,

can someone please try this out:

printf "%05d" 08

it says 'invalid number' for any number of 0's before the 8. Why does it 
think it's octal ?! Both the shell version and the executable have the 
same problem, so I guess it's a shell problem. This also explains 
problems I had some time ago composing a shell script on this machine 
(I started a thread on this list about that - some numbers used to 
disappear for no reason - the numbers were sequential filename in aa 
script).

Again:

/usr/bin/printf "%05d" 08
/usr/bin/printf: 08: value not completely converted

printf "%05d" 08
-bash: printf: 08: invalid number

printf "%05d" 10#08
-bash: printf: 10#08: invalid number

(according to the bash manual that notation should force decimal - it 
does not - not in quotes and not in ticks and not with a 
backslash-escaped '#').

I wrote a small C program to test atoi, strtod and strtoul and the 
latter is broken (is it ?). E.g.:

plp at plp:~/tc$ ./1 07
atoi: 7
strtod: 7.000000
strtoul: 7
plp at plp:~/tc$ ./1 08
atoi: 8
strtod: 8.000000
strtoul: 0

I take this to mean that strtoul() assumes the lowest conversion base it 
can use if the third argument is 0. This is a bug. It should look at the 
whole string and match the highest base it can, starting from the last 
character that is not convertible with any base, imho. My program linked 
(automatically) against libc.so.6 (0x40025000). This system is Debian 
based. The program is available (I will post it here if needed).

?! tia,
Peter
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list