The mksh implementation of test/[ incorrectly returns an exit status of 0 (success) if one of the operands to an operator is invalid. An example:
$ test 2 -eq 2a && echo false-positive mksh: 2a: bad number '2a' false-positive I wrote the attached patch which I believe fixes the problem. Please verify. Thanks, - Martijn Dekker (Groningen, Netherlands)
diff -ur mksh.orig/funcs.c mksh/funcs.c --- mksh.orig/funcs.c 2015-07-11 01:01:24.000000000 +0100 +++ mksh/funcs.c 2015-12-11 21:44:19.000000000 +0000 @@ -2861,7 +2861,10 @@ ptest_unary: rv = test_eval(&te, op, *te.pos.wp++, NULL, true); ptest_out: - return ((invert & 1) ? rv : !rv); + if (te.flags & TEF_ERROR) + return (T_ERR_EXIT); + else + return ((invert & 1) ? rv : !rv); } /* let the parser deal with anything else */ break;