Improve shell builtin exit codes#14
Conversation
Fixes multiple cases where a builtin was not setting its own exit code or returned success on failure. Adds related tests.
|
Can you elaborate on 'weirdly'? It's tough to see what the concrete changes are just from the PR diff. |
|
Of course. I noticed two classes of errors:
I've included a test in the commit, With the patch, the output is:
|
| # break, continue, exit, return and newgrp are not tested. | ||
| COMMANDS=": shift unset export readonly local times eval source exec | ||
| set trap true false pwd echo cd hash type command umask alias unalias | ||
| wait jobs read test [ printf kill getopts fg bg help history fc |
There was a problem hiding this comment.
fc probably shouldn't be in this list, as it only really has meaning in an interactive shell. (See https://pubs.opengroup.org/onlinepubs/9699919799/utilities/fc.html) It's harmless to have it for now, though.
|
The good news is that this all looks fine. The bad news is that it isn't passing the POSIX test suite. The still worse news is that neither are old, known-good builds. There's some bug that's breaking my setup. I'd wager it's in the Docker toolchain or the Debian 9 image I'm using. In any case, I'm going to try to debug the issue before I merge this patch (or #15). Sorry for the delay, and I'm very glad you submitted these... thank you! |
|
I noticed that |
|
That's probably too much of a hack for me... but the Lem library has a Another option would be to put the |
|
I added a commit that makes I couldn't find anything in the standard that would make this required or forbid it, but Modernish uses it and it seems useful. |
|
Oh, I think it's implicit in "found using the PATH variable" in https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html. [https://github.com/mgree/smoosh/blob/master/BUG.command.-v.builtin.path.test] is about this behavior. |
|
Right, but this is for when it is given as an absolute path. Example: now becomes |
|
Ahhh. I see. The I imagine that ~/smoosh/tests/cmp$ ./test.sh 'command -V /none/such'
smoosh: OUT [/none/such is /none/such] ERR [] EC [0]
bash-posix: OUT [] ERR [bash: line 0: command: /none/such: not found] EC [1]
bash: OUT [] ERR [bash: line 0: command: /none/such: not found] EC [1]
dash: OUT [/none/such: not found] ERR [] EC [127]
zsh-posix: OUT [/none/such not found] ERR [] EC [1]
zsh: OUT [/none/such not found] ERR [] EC [1]
osh: OUT [] ERR [ command -V /none/such
^~
[ -c flag ]:1: 'command' doesn't accept flag '-V'] EC [2]
mksh: OUT [/none/such not found] ERR [] EC [1]
ksh: OUT [] ERR [ksh: command: /none/such: not found] EC [1]
yash-posix: OUT [] ERR [command: no such command `/none/such'] EC [1]
yash: OUT [] ERR [command: no such command `/none/such'] EC [1] |
|
Another small change for |
I noticed that some builtins behave weirdly when failing, this should make the situation a bit more consistent.