Closed ihar-orca closed 1 year ago
Thanks for reporting. Want to send a PR? We should check other forms of arithmetic expressions too, like let x=" 3 "
or your example with [[
as well.
no, currently I don't have any relevant and correct PR. for the local issue I just made a call for strings.TrimSpace
inside each atoi
but I think it's not the best idea.
For the record, this is a simple form of https://github.com/mvdan/sh/issues/754. When it comes to arithmetic expressions, we don't expand quoted strings into fields. If we did that, then the spaces would go away in your example.
That said, this scenario is indeed easy to solve with TrimSpace, so it seems fine to me. cc @riacataquian
It seems that the Bash trims spaces before integer comparison:
The sh/interp uses strict comparision rules and does not use any space trim functions before the binary tests that are defined in
interp/test.go
(binTest
func,atoi
).