`test ! = -o a` exits with 0 instead of 1
vinc17fr opened this issue · 5 comments
With ksh93u+m 1.0.8-1 under Debian/unstable:
$ test ! = -o a ; echo $?
0
while I get 1 with dash 0.5.12-6, mksh 59c-35, bash 5.2.21-2, coreutils 9.4-3.1 and zsh 5.9-6.
In the POSIX spec of test
for 4 arguments:
If $1 is '!', negate the three-argument test of $2, $3, and $4.
The negation is not what is done:
$ test = -o a ; echo $?
0
Hmm... I can see that setting the posix
option with set -o posix
gives the expected result.
Note that in general, the main purpose of the test
command in shells is to get the POSIX behavior. Otherwise, [[ ... ]]
should be used instead. So I'm wondering why the POSIX behavior is not the default for test
.
Note that in general, the main purpose of the test command in shells is to get the POSIX behavior. Otherwise, [[ ... ]] should be used instead.
“Should be” != “is”. There are plenty of ksh scripts that use test
/ [
. Backward compatibility is important.
So I'm wondering why the POSIX behavior is not the default for
test
.
Backward compatibility. See 9b259c9 for reasons.
I will see what can be done about fixing the reproducer above. But I'm not making any promises. Messing with the test
code carries a high risk of introducing new bugs and backward incompatibilities.
In any case, I always thought that ksh was meant to conform to POSIX. For instance, this is how it is advertised (with no warnings about this not being the default behavior)
- by IBM: "The Korn shell is an interactive command interpreter and command programming language. It conforms to the Portable Operating System Interface for Computer Environments (POSIX), an international standard for operating systems."
- by Debian, in the ksh93u+m package description: "KornShell is an interactive UNIX command interpreter as well as a POSIX compliant scripting language which is a superset of sh(1), the System V UNIX shell."
In any case, I always thought that ksh was meant to conform to POSIX.
Yes, that's how it was always advertised, but it's just not quite true. I've found many ways in which traditional ksh93 behaviour is not compliant with the POSIX standard. Fixing that by default would break compatibility with too many ksh scripts, which is why I've added a posix
compliance option. See the manual page under Built-in Commands
→ set
→ -o
→ posix
for a list of these differences.
I will see what can be done about fixing the reproducer above. But I'm not making any promises. Messing with the
test
code carries a high risk of introducing new bugs and backward incompatibilities.
There is no easy way to fix this, and it's not worth the high risk of introducing new bugs.