Skip to content

[redirection] 未加引号未设置变量重定向误判:>$TMPF 报 : No such file or directory 且管道 rc=1(GNU ambiguous redirect、rc=0;#265 未覆盖零字段路径) #514

Closed

Description

@caomengxuan666

复现(TMPF 未设置)

printf '%d\n' abc 2>&1 >$TMPF | cat
stdout+stderr rc
GNU bash 5.3.0 bash: line 1: $TMPF: ambiguous redirect 0
rubash 764b9dd ...: : No such file or directory 1

双重分歧:

  1. 错误类别:未加引号的 $TMPF 展开为零字段 → bash 判 ambiguous redirect(消息携带原始词 $TMPF);rubash 判成打开空路径 ENOENT(消息只有空词)。
  2. 退出语义:管道某 stage 重定向失败时 bash 中止该 stage 但管道继续,整体 rc = 末位 stage(cat,读 EOF 正常)= 0;rubash 整体 rc=1。

与 #265 的关系

#265(已关闭)修的是带引号空串(> "" → : No such file or directory、>& "" → raw-word Bad file descriptor)。本例是未加引号的未设置变量(展开为零字段)→ bash 仍走 ambiguous redirect 分支,rubash 却落入了 #265 修复后的 ENOENT 分支。#265 的修复未覆盖零字段情形,且 >& 路径(见重定向消息保真 issue)仍泄漏内部标记。

规范/源码依据

  • XCU 2.7 Redirection:重定向词展开后字段数 ≠1 为歧义;bash redir.c 对零字段输出 "ambiguous redirect" 并携带原词回显。
  • 管道语义:stage 重定向失败只废弃该 stage,pipestatus 与整体 rc 按其余 stage 计算(bash 手册 PIPESTATUS/pipeline 节)。

跨实现互证(huck)

证据

  • 语料出处:builtin_stage_stderr_diff_check.sh:42(F043,label: builtin-interleave)
  • 复核:764b9dde 仍复现;旧构建 41de831 行为一致

Activity

  1. added
    bug
    P2-medium
    on Oct 12, 2026
  2. caomengxuan666 commented on Oct 12, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by #576 (Wave4a). Vendored-bash anchors and RED-then-GREEN regression evidence in the PR.

  3. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions