Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test ! = -o a exits with 0 instead of 1 #740

Open
vinc17fr opened this issue Apr 4, 2024 · 4 comments
Open

test ! = -o a exits with 0 instead of 1 #740

vinc17fr opened this issue Apr 4, 2024 · 4 comments

Comments

@vinc17fr
Copy link

vinc17fr commented Apr 4, 2024

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
@vinc17fr
Copy link
Author

vinc17fr commented Apr 4, 2024

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.

@McDutchie
Copy link

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.

@vinc17fr
Copy link
Author

vinc17fr commented Apr 8, 2024

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."

@McDutchie
Copy link

McDutchie commented Apr 20, 2024

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 Commandsset-oposix for a list of these differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants