2021-06-28 12:06:34 +0100, Geoff Clare via austin-group-l at The Open Group: [...] > > It has been tradition, for a very long time, for writes on stdout to > > have errors ignored - particularly in a case like this, where because > > of the redirection, stdout is probably buffered, and not a lot is > > written, so the actual write that encounters the error most likely > > happens during exit() processing (flushing stdio buffers). > > You are talking about pre-POSIX tradition. The rules in POSIX.2 should > have put an end to that ancient dodgy behaviour when systems were > updated to conform to POSIX. [...]
I'd argue that if POSIX wanted that to change, it should have made it a lot clearer / more explicit. On Solaris 11 (certified as compliant): $ /bin/sh -c 'pwd; echo "$?" >&2' >&- 0 /export/home/chazelas pwd (here ksh93 builtin) returns success, the working directory printed upon exit as stdout was somewhat reopened (that's more of a bug though). $ /usr/xpg4/bin/sh -c 'pwd; echo "$?" >&2' >&- 0 $ /usr/xpg4/bin/grep root /etc/passwd >&-; echo "$?" 0 (same for echo, printf...) -- Stephane
