On 2023-10-28 18:41, Oğuz wrote:
Why? The same commands fail on bosh, yash, and zsh too.

I don't know what bosh is. zsh and yash prohibit trailing spaces in integers, but allow leading spaces:

  % test ' 3' -lt ' 4'
  % test ' 3 ' -lt ' 4 '
  test: integer expression expected:  3

Presumably this is because they use strtol or equivalent, and accept exactly the strings that strtol accepts. Although that's an allowed behavior, it's not the behavior that Bash and ksh and Dash use; they both allow the second example listed above.

My understanding is that Bash was intended to allow both leading and trailing whitespace. This is compatible with ksh and with Dash. If that's the intent, Bash should be consistent about it, just as ksh and Dash are. There seems little point to allowing one nonempty set of whitespace characters before the integer, and a different nonempty set of whitespace characters afterwards.

For what it's worth, 7th Edition Unix sh allows any characters after the integer. (There doesn't even have to be an integer!)

PS. As I understand it, POSIX allows all the behaviors described above, so this is not a POSIX conformance issue.

Reply via email to