diff --git a/Src/exec.c b/Src/exec.c index 2b8e2167f..be949049f 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -726,7 +726,7 @@ execute(LinkList args, int flags, int defpath) (arg0[0] == '.' && (arg0 + 1 == s || (arg0[1] == '.' && arg0 + 2 == s)))) { zerr("%e: %s", lerrno, arg0); - _exit((lerrno == EACCES || lerrno == ENOEXEC) ? 126 : 127); + _exit((lerrno == 0 || lerrno == ENOENT) ? 127 : 126); } break; } @@ -805,7 +805,7 @@ execute(LinkList args, int flags, int defpath) _realexit(); else zerr("command not found: %s", arg0); - _exit((eno == EACCES || eno == ENOEXEC) ? 126 : 127); + _exit((eno == 0 || eno == ENOENT) ? 127 : 126); } #define RET_IF_COM(X) { if (iscom(X)) return docopy ? dupstring(X) : arg0; } diff --git a/Test/A05execution.ztst b/Test/A05execution.ztst index edc561582..64fdd8288 100644 --- a/Test/A05execution.ztst +++ b/Test/A05execution.ztst @@ -394,3 +394,13 @@ F:anonymous function, and a descriptor leak when backgrounding a pipeline >127 # TBD: the 0 above is believed to be bogus and should also be turned # into 127 when the ccorresponding bug is fixed in the main shell. + +# Test for exit status 126 when an external command's argument list is too long. + v=foo_bar_baz_quux_lorem_ipsum_dolor_sit_amet + while :; do + v=$v$v$v$v$v$v$v$v + env true $v || { print $?; break; } + done +0:exit status when argument list too long +>126 +?(eval):4: argument list too long: env