Skip to content

Commit

Permalink
Pass exit status to parent on Ctrl+D
Browse files Browse the repository at this point in the history
Reproducer:

    $ ksh
    $ false
    $ ^D
    (child ksh exits)
    $ echo $?
    0

Expected output: 1, the exit status of 'false'. All shells except
ksh93 pass the exit status of the last-executed command and this is
also the POSIX standard behaviour.

src/cmd/ksh93/sh/main.c: exfile():
- At the 'eof_or_error:' label, add a missing restore of the
  current exit status before jumping to 'done'.
  • Loading branch information
McDutchie committed Feb 12, 2024
1 parent cbc9027 commit 00a36f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
- Fixed a bug, introduced on 2023-06-02, that made it impossible within a
namespace to unset a function defined outside the namespace.

- Fixed: ksh didn't pass the exit status of the last command it executed to
the parent process on entering EOF (Ctrl+D) on a terminal.

2024-02-09:

- Fixed multiple inaccurate or missing values in the /opt/ast/bin/getconf
Expand Down
1 change: 1 addition & 0 deletions src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ static void exfile(Sfio_t *iop,int fno)
sfclrerr(iop);
continue;
}
sh.exitval = sh.savexit;
goto done;
}
sh.exitval = sh.savexit;
Expand Down

0 comments on commit 00a36f2

Please sign in to comment.