## 复现(stdin 驱动:`printf '%s' "$s" | shell`,5 个片段同一根因) ```bash echo "${x:- # F120 ``` ```bash x=axb; echo "${x# # F123 ``` ```bash $(m ' # F127 ``` ```bash echo a\necho b\n'unterminated # F128 ``` ```bash echo "$ # F139 ``` | 片段 | GNU bash 5.3.0 | rubash 764b9dde | |---|---|---| | F120 | `bash: line 1: unexpected EOF while looking for matching `}'`,**rc=2** | 消息同(仅程序名差),**rc=0** | | F123 | 同上 matching `}',rc=2 | rc=0 | | F127 | 同上 matching `'',rc=2 | rc=0 | | F128 | 同上 matching `'',rc=2 | rc=0 | | F139 | 同上 matching `"‘,rc=2 | rc=0 | 调用方(`rubash < script || handler`)靠退出码判断成败,rc=0 会让 `||` 分支失效。 ## 根因(已细化:stdin 路径特有) 同一片段**从脚本文件执行时 rubash rc=2 正确**: ``` $ rubash t_eof.sh → rc=2 ✔ $ printf '%s\n' 'echo "${x:-' | rubash → rc=0 ✘ ``` 退出码丢失发生在 **stdin(管道/重定向文件)读取路径**:语法错误诊断正常打印,但顶层的 exit status 未置 2。(F181 `x='abc{def'; echo \${x%%[<{(]*}` 的 rc=0 同属此退出码管线,其消息形状差异另见命令位置 `(` 的 issue。) ## 规范/源码依据 - bash 对非交互 shell 的语法错误固定以 2 退出(bash 源码 error.h:`EX_SYNTAXERR = 2`;顶层解析错误路径 exit_shell(EX_SYNTAXERR))。 - 与读取通道无关:文件与 stdin 的差异只应影响提示形式,不应影响退出码。 ## 跨实现互证(huck) - [huck#284 "Non-interactive piped stdin recovers across a newline after a syntax error where bash aborts"](https://github.com/jdstanhope/huck/issues/284)(已修复)——同轴:huck 的 stdin 驱动语法错误处理与 bash 分歧,已按 bash 修正。 - [huck#332 "huck resets $? to 0 on an empty/comment/blank line; bash preserves it"](https://github.com/jdstanhope/huck/issues/332)(已修复)——stdin 驱动的状态管理同点。 - [huck#198 "Architecture: unify the error-fatality decision (abort vs continue, and exit code) across error sites"](https://github.com/jdstanhope/huck/issues/198)(已关闭)——错误致命性/退出码决策应统一收口,与本根因(诊断对了、退出码漏了)完全同构。 ## 证据 - 语料出处:operand_dquote_context / pattern_operand_quoting / pattern_chokepoint / script_parse_error / dollar_quote_forms 五个 harness(F120/F123/F127/F128/F139) - 复核: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).