## 复现 ```bash exec >&-; printf "end\n" ``` | | stdout+stderr | rc | |---|---|---| | GNU bash 5.3.0 | `bash: line 1: printf: write error: Bad file descriptor` | **1** | | rubash 764b9dde | `...rubash.exe: line 1: printf: write error: Bad file descriptor`(消息一致) | **0** | ## 根因 printf 检测到了写失败并打印了与 GNU 相同的诊断,但没有把失败反映到退出码——写失败的退出状态被丢弃。`exec >&-` 防呆 + `printf ... || fail` 是脚本常用模式,rc=0 会静默吞掉数据未落盘的事实。 ## 规范/源码依据 - bash 内建 printf:写失败 → 报 `printf: write error: ...` 且内建返回 1(builtins/printf.def:write error 路径置 exit_status=1)。 - POSIX printf 工具约定:发生写错误时退出状态 >0。 ## 跨实现互证(huck) - [huck#137 "Builtin `echo`/`printf` write error to a closed/failed stdout is silently swallowed (rc 0, bash rc 1)"](https://github.com/jdstanhope/huck/issues/137)(已修复)——**逐字同一语义点**。 - [huck#186 "Builtin writes to a read-only fd silently succeed (rc 0); bash reports "write error: Bad file descriptor" and rc 1"](https://github.com/jdstanhope/huck/issues/186)(已修复)——同族(写失败判定面更宽)。 ## 证据 - 语料出处:builtin_write_error_diff_check.sh:46(fragment F145,label: printf-closed) - 复核:764b9dde 仍复现;旧构建 41de8319 行为一致
Activity
fix: P1 semantic batch - errexit body adjudication, stdin rc, write-f…
caomengxuan666 commentedon Oct 12, 2026
Fixed and merged (see the linked PR in timeline).