Ken Irving wrote: >> $ printf "%d %s\n" 1 ok - >> 1 ok >> -bash: printf: -: invalid number >> 0 >> >> why getting error here, and not in the previous? >> why "invalid number" ? >> what is that zero? > > Again, you have more arguments than operators, so it makes another pass, > and on the second pass tries to format - as a number... Don't know > about the zero, but I guess %d maybe starts with a default of 0...?
When bash detects an integer conversion error, it returns 0. That's not strictly Posix-conformat, so the next version of bash will return whatever strtoimax/strtoll/strtol returns, which is supposed to be the value accumulated up to the point of the error. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/