[] is actually shorthand for the test command in bash. That is, all [expr] equals test expr
For the test command, use-eq to make a numeric comparison, and when you pass in the string, you get an error.
[[expr]] is a real conditional judgment statement in Bash whose syntax is more in line with programming habits (such as &&, | | ), although I think the intentional string to-eq in [[]] should also be as error as test, but it is obvious that the bash implementation directly converts a non-integer string directly to 0 (you can verify it yourself, in [[]], any need for an integer, but the supply is indeed another that cannot be converted to an integer String, all of them become 0). This should be the result of a bash implementation that does not check for content on either side of the-EQ operator in [[]]. For us, there is no need to drill these things, and we should make sure that we always provide integers when we need to use integers in our code.
The main differences between [[]] and [] in the shell