Skip to content

[bug] script-file argument open failure exits 1 instead of 127 (ENOENT) / 126 (EISDIR etc.) — shell.c open_shell_script EX_NOTFOUND/EX_NOINPUT unmapped #262

Closed

Description

@caomengxuan666

Summary

When the script-file argument cannot be opened, rubash reports the right diagnostic but exits with the wrong status: 1 where GNU bash 5.3.0 exits 127 (missing file, ENOENT) or 126 (directory / non-ENOENT). The status code is contractual: make, CI drivers and test harnesses branch on 127 vs 126 vs 1.

Found by the corpus3 lane while running the OpenSSH 9.9p2 configure comparison (a mistyped corpus path exposed the divergence), then minimized.

Owning GNU code

third_party/bash/shell.c:1572 open_shell_script() — on open failure:

if (fd < 0)
  {
    e = errno;
    file_error (filename);
    ...
    sh_exit ((e == ENOENT) ? EX_NOTFOUND : EX_NOINPUT);
  }

with shell.h:66 #define EX_NOTFOUND 127 and shell.h:65 #define EX_NOINPUT 126. The directory case is the same function, slightly below (file_isdir → sh_exit (EX_NOINPUT)).

Probe (identical invocation on both shells, script-file methodology)

invocation WSL GNU Bash 5.3.0 rubash (8681835)
bash -n missing.sh stderr bash: missing.sh: No such file or directory, rc=127 stderr ...: missing.sh: No such file or directory, rc=1
bash missing.sh (exec) same stderr, rc=127 same stderr, rc=1
bash <existing-directory> ...: Is a directory, rc=126 ...: Permission denied, rc=1

Raw GNU oracle output (WSL):

$ /usr/local/bin/bash -n /tmp/definitely-missing-file-xyz.sh ; echo "gnu -n rc=$?"
/usr/local/bin/bash: /tmp/definitely-missing-file-xyz.sh: No such file or directory
gnu -n rc=127
$ /usr/local/bin/bash /tmp/definitely-missing-file-xyz.sh ; echo "gnu exec rc=$?"
/usr/local/bin/bash: /tmp/definitely-missing-file-xyz.sh: No such file or directory
gnu exec rc=127

Note the directory case also diverges in message text (Is a directory vs Permission denied) — that part is Windows errno rendering (opening a directory yields EACCES on Windows) and may be platform-bound, but the exit-status mapping is rubash-caused and fixable regardless of the errno question.

Fix direction

Map script-open failure exit status per open_shell_script: ENOENT → 127 (EX_NOTFOUND), other open errors → 126 (EX_NOINPUT). Fixture: tests/fixtures/corpus3/repro/script_open_exit_status.sh.

Environment

  • rubash 8681835 (wt5/corpus3), Windows 10 19044
  • Oracle: WSL GNU Bash 5.3.0 /usr/local/bin/bash
  • Artifacts: target/issue-suites/results/corpus3/results/openssh-n/ (accidental live capture: gnu rc=127 vs rub rc=1 on identical missing-path args), work/missing-probe.sh, work/dir-probe*.sh

Activity

  1. added
    bug
    on Sep 27, 2026
  2. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit 2c78889b,lane wt6/builtin2;GNU 引用与全矩阵验证见提交——回归 24/24、set-e/set-x/errors 真基线平价)。感谢报告!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions