* src/test.c (binop): Recognize the ">" and "<" operators.
(three_arguments): Likewise.
(binary_operator): Implement the "<" and ">" operators.
(usage): Add operators to --help output.
* tests/test/test.pl (@Tests): Add functionality tests.
* doc/coreutils.texi (test invocation, String tests): Document new
operators.
* NEWS: Mention the new feature.
%<i>$ format, where '<i>' is an integer referencing a particular argument,
thus allowing repetition or reordering of printf arguments.
+ test supports the POSIX:2024 specified '<' and '>' operators with strings,
+ to compare the string locale collating order.
+
timeout now supports the POSIX:2024 specified -f, and -p short options,
corresponding to --foreground, and --preserve-status respectively.
* File type tests:: @code{-[bcdfhLpSt]}
* Access permission tests:: @code{-[gkruwxOG]}
* File characteristic tests:: @code{-e -s -nt -ot -ef}
-* String tests:: @code{-z -n = == !=}
+* String tests:: @code{-z -n = == != > <}
* Numeric tests:: @code{-eq -ne -lt -le -gt -ge}
* Connectives for test:: @code{! -a -o}
@end menu
@cindex not-equal string check
True if the strings are not equal.
+@item @var{string1} > @var{string2}
+@opindex >
+@cindex greater-than string check
+True if @var{string1} is greater than @var{string2} in the current locale.
+
+@item @var{string1} < @var{string2}
+@opindex <
+@cindex less-than string check
+True if @var{string1} is less than @var{string2} in the current locale.
+
@end table
binop (char const *s)
{
return ((STREQ (s, "=")) || (STREQ (s, "!=")) || (STREQ (s, "==")) ||
- (STREQ (s, "-nt")) ||
+ (STREQ (s, "-nt")) || (STREQ (s, ">")) || (STREQ (s, "<")) ||
(STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
(STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
(STREQ (s, "-gt")) || (STREQ (s, "-ge")));
* '-t' int
* '-'('z'|'n') string
* string
- * string ('!='|'=') string
+ * string ('!='|'='|>|<) string
* <int> '-'(eq|ne|le|lt|ge|gt) <int>
* file '-'(nt|ot|ef) file
* '(' <expr> ')'
return value;
}
+ if (STREQ (argv[op], ">"))
+ {
+ bool value = strcoll (argv[pos], argv[pos + 2]) > 0;
+ pos += 3;
+ return value;
+ }
+
+ if (STREQ (argv[op], "<"))
+ {
+ bool value = strcoll (argv[pos], argv[pos + 2]) < 0;
+ pos += 3;
+ return value;
+ }
+
/* Not reached. */
affirm (false);
}
value = one_argument ();
advance (false);
}
- else if (STREQ (argv[pos + 1], "-a") || STREQ (argv[pos + 1], "-o"))
+ else if (STREQ (argv[pos + 1], "-a") || STREQ (argv[pos + 1], "-o")
+ || STREQ (argv[pos + 1], ">") || STREQ (argv[pos + 1], "<"))
value = expr ();
else
test_syntax_error (_("%s: binary operator expected"),
-z STRING the length of STRING is zero\n\
STRING1 = STRING2 the strings are equal\n\
STRING1 != STRING2 the strings are not equal\n\
+ STRING1 > STRING2 STRING1 is greater than STRING2 in the current locale\n\
+ STRING1 < STRING2 STRING1 is less than STRING2 in the current locale\n\
"), stdout);
fputs (_("\
\n\
['paren-3', "'(' ')' ')'"],
['paren-4', "'(' ! ')'"],
['paren-5', "'(' -a ')'"],
+
+ ['less-collate-1', "'a' '<' 'b'"],
+ ['less-collate-2', "'a' '<' 'a'", {EXIT=>1}],
+ ['less-collate-3', "'b' '<' 'a'", {EXIT=>1}],
+
+ ['greater-collate-1', "'b' '>' 'a'"],
+ ['greater-collate-2', "'a' '>' 'a'", {EXIT=>1}],
+ ['greater-collate-3', "'a' '>' 'b'", {EXIT=>1}],
);
@Tests = add_inverse_op_tests \@Tests;