On Wed, 20 Nov 2024, 07:36 Paul Eggert, <egg...@cs.ucla.edu> wrote: > However, I don't see why Bash should differ from POSIX behavior. Bash > already diagnoses "printf %d x" and "printf %d ' '"; why should it be > silent about "printf %d ''"? >
>From a semantic perspective, because "" doesn't contain any non-digits. >From an implementation perspective, the standard check for a valid number is to call strtol() (or similar) and then see if there are any non-digits remaining. It takes an extra check to see if it stopped without processing any digits. I'm in favour of treating the empty token (string) as being a valid way to write zero, in the same way that 00 and 0000000 are also valid ways to write zero. That makes it more consistent in ways that are useful. I've heard appeals to "human" ways of writing numbers as a reason to forbid treating an empty token as a valid way to write zero. I find such appeals quite unconvincing, for the simple reason that human languages languages have no rules at all for handling empty tokens (because they're indistinguishable from no token at all). -Martin