On Sun, 9 Jun 2024, Ralph Corderoy wrote:
Some historical implementations returned exit status zero even if command errors had occurred; this is not allowed by this volume of POSIX.1‐2008.
Here is what I think it means: it is an error to exit with zero in case
the error occurred, i.e. right away after an error.
This needs to be read in the context of a CONSEQUENCES OF ERROR
section (quoting 2017 version from [1]):
ONSEQUENCES OF ERRORS
When an error in the input script is encountered, or when an error
is detected that is a consequence of the data (not) present in the
file or due to an external condition such as a read or write error:
If the standard input is a terminal device file, all input shall
be flushed, and a new command read.
If the standard input is a regular file, ed shall terminate with
a non-zero exit status.
The whole concept to have a temporary variable to taint the future
exit status is wrong (cleanup code executed before the exit does not count).
If there is an error that you consider serious enough to exit and
set an exit code, the systems EXITS and sets the code.
If there is a heuristic that determines the program to be interactive
enough to allow the execution to proceed and ask the user to re-enter
a possibly new command, no exit code should be determined - simply
because we do not, er, exit.
I think GNU ed introduced this at a (possibly misguided) attempt
to remove isatty at the very beginning.
[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html
Marcin
smime.p7s
Description: S/MIME Cryptographic Signature
