Commit 730ee299 authored by jan.koester's avatar jan.koester
Browse files

test: string comparison with > and <

`test "$(RUSTC_VERSION)" ">" "1.74"` (mrustc's run_rustc Makefile) was an
unknown operator, exit 2 -- the old sh hid it by taking the quoted ">" for
a redirection (fixed in 9863abfa), which left `test "1.90.0"`, always true.
> and < now compare as strings, as POSIX 2024, bash and dash do.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 9863abfa
Loading
Loading
Loading
Loading
+4 −0
Changes for commands/shell/test.cpp: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -77,6 +77,10 @@ namespace fresh {

            if(op=="=" || op=="==") result=(strcmp(lhs,rhs)==0);
            else if(op=="!=") result=(strcmp(lhs,rhs)!=0);
            // string order (POSIX 2024, bash, dash): make's version checks,
            // e.g. test "$(RUSTC_VERSION)" ">" "1.74"
            else if(op==">") result=(strcmp(lhs,rhs)>0);
            else if(op=="<") result=(strcmp(lhs,rhs)<0);
            else if(op=="-eq") result=(atol(lhs)==atol(rhs));
            else if(op=="-ne") result=(atol(lhs)!=atol(rhs));
            else if(op=="-lt") result=(atol(lhs)<atol(rhs));