#1051076 dash: test does not support s1 < s2 or s1 > s2

Package:
dash
Source:
dash
Description:
POSIX-compliant shell
Submitter:
Gian Piero Carrubba
Date:
2024-02-28 08:03:05 UTC
Severity:
normal
Tags:
#1051076#5
Date:
2023-09-02 10:55:34 UTC
From:
To:
dash supposedly implements test s1 < s2 and test s1 > s2 for string
comparisons. A cursory glance at [0], [1] and [2] seems to confirm this.

Anyway the shell redirection seems to take precedence so that the test
is not actually performed.
$ type test
test is a shell builtin
$ ls -l bar
ls: cannot access 'bar': No such file or directory
$ test "foo" < "bar"
dash: 2: cannot open bar: No such file
$ test "foo" > "bar"
$ ls -l bar
-rw-r--r-- 1 gpiero gpiero 0 Sep  2 12:51 bar

As a side note, '<' and '>' are not mandated by POSIX [3].

Thanks,
Gian Piero.

[0] https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/dash.1
[1]
https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/bltin/test.1
[2]
https://git.kernel.org/pub/scm/utils/dash/dash.git/tree/src/bltin/test.c
(STRLT and STRGT)
[3] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

#1051076#10
Date:
2023-09-02 13:24:13 UTC
From:
To:
severity 1051076 grave
thanks

Thinking about it, grave seems a more appropriate severity as the issue
could cause data loss in case s2 happens to be the pathname of an
existent file when using the form `test s1 > s2`.

#1051076#17
Date:
2023-09-03 08:59:37 UTC
From:
To:
Control: severity -1 normal
Control: tag -1 wontfix

You forgot to escape the < and >:

$ test foo '>' bar
$ echo $?
0
$ test foo '<' bar
$ echo $?
1