summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/builtin.c4
-rw-r--r--Src/parse.c8
-rw-r--r--Test/C02cond.ztst6
4 files changed, 21 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7fc4d4ffe..3668b7786 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2025-11-24 Oliver Kiddle <opk@zsh.org>
+ * 54103: Src/builtin.c, Src/parse.c, Test/C02cond.ztst:
+ support > and < comparisons via the test builtin
+
* 54094: Completion/Unix/Command/_base64,
Completion/Unix/Command/_basename, Completion/Unix/Command/_cat,
Completion/Unix/Command/_chmod, Completion/Unix/Command/_chown,
diff --git a/Src/builtin.c b/Src/builtin.c
index 1c0eb331e..ba2fe1cdf 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -7243,6 +7243,10 @@ testlex(void)
tok = INPAR;
else if (!strcmp(*testargs, ")"))
tok = OUTPAR;
+ else if (!strcmp(*testargs, "<"))
+ tok = INANG;
+ else if (!strcmp(*testargs, ">"))
+ tok = OUTANG;
else
tok = STRING;
testargs++;
diff --git a/Src/parse.c b/Src/parse.c
index 0ba7c701c..ab708a279 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2495,6 +2495,8 @@ par_cond_2(void)
/* three arguments: if the second argument is a binary operator, *
* perform that binary test on the first and the third argument */
if (!strcmp(*testargs, "=") ||
+ !strcmp(*testargs, "<") ||
+ !strcmp(*testargs, ">") ||
!strcmp(*testargs, "==") ||
!strcmp(*testargs, "!=") ||
(IS_DASH(**testargs) && get_cond_num(*testargs + 1) >= 0)) {
@@ -2661,6 +2663,12 @@ par_cond_triple(char *a, char *b, char *c)
ecstr(a);
ecstr(c);
ecadd(ecnpats++);
+ } else if ((t0 = (b[0] == '>' || b[0] == Outang) ||
+ b[0] == '<' || b[0] == Inang) && !b[1]) {
+ ecadd(WCB_COND(t0 ? COND_STRGTR : COND_STRLT, 0));
+ ecstr(a);
+ ecstr(c);
+ ecadd(ecnpats++);
} else if ((b[0] == Equals || b[0] == '=') &&
(b[1] == Equals || b[1] == '=') && !b[2]) {
ecadd(WCB_COND(COND_STRDEQ, 0));
diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst
index daea5b4f8..3910f705f 100644
--- a/Test/C02cond.ztst
+++ b/Test/C02cond.ztst
@@ -214,6 +214,12 @@ F:scenario if you encounter it.
[ '' != bar -a '' = '' ]
0:strings with `[' builtin
+ [ zzd '>' zzb -a e '<' x ]
+0:string comparisons with `[' builtin
+
+ [ -o \> -a ]
+0:string comparison with strings that look like operators
+
[ `echo 0` -lt `echo 1` ]
0:substitution in `[' builtin