Chet Ramey <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> Is this a bug? >> >>>> $ t=test #bash builtin >>>> $ $t -t ' '; echo $? >>>> 0 > > Doesn't look like it:
I think it is a bug, but libc may or may not hide it, depending on the strtol[l] implementation. SUS says: # If the subject sequence is empty or does not have the expected form, # no conversion is performed; the value of str is stored in the object # pointed to by endptr, provided that endptr is not a null pointer. ... # If no conversion could be performed, 0 shall be returned and errno may # be set to [EINVAL]. Note it says "errno may be set", not "shall". bash seems to assume "shall" in legal_number() in general.c: errno = 0; value = strtoimax (string, &ep, 10); if (errno) return 0; /* errno is set on overflow or underflow */ I think the test should be: if (errno || ep == string) This should be reliable, according to SUS: # If the subject sequence is empty or does not have the expected form, # no conversion is performed; the value of str is stored in the object # pointed to by endptr, provided that endptr is not a null pointer. paul