Currently, when a utility fails to execute due to something like E2BIG,
mksh sets the exit status to 1. That is not satisfactory because there
is no way to distinguish this error by exit status from a normal 1 for
false/no match/etc. from utilities such as grep.
Generally accepted convention is to return status 126 in such cases, as
done by ksh93, bash, yash, dash (current git), FreeBSD sh, and NetBSD
sh. The attached patch makes that happen.
Test script:
v=foo_bar_baz_quux_lorem_ipsum_dolor_sit_amet
while :; do
v=$v$v
sh -c ":" -- "$v" || { echo "status $?"; exit; }
done
Current output:
longargs.sh[8]: /bin/sh: Argument list too long
status 1
Expected output:
longargs.sh[8]: /bin/sh: Argument list too long
status 126
Thanks,
- M.
--
modernish -- harness the shell
https://github.com/modernish/modernish
diff --git a/exec.c b/exec.c
index 8231b54..01135c4 100644
--- a/exec.c
+++ b/exec.c
@@ -446,7 +446,7 @@ execute(struct op * volatile t,
if (rv == ENOEXEC)
scriptexec(t, (const char **)up);
else
- errorf(Tf_sD_s, t->str, cstrerror(rv));
+ errorfx(126, Tf_sD_s, t->str, cstrerror(rv));
}
Break:
exstat = rv & 0xFF;