Skip to content

[bug] declare -p NAME not-found diagnostic is empty inside a command substitution (top-level matches GNU) #189

Closed

Description

@caomengxuan666

Reproducer (LF script file, both shells)

unset ZZQ
V=$(declare -p ZZQ 2>&1)
echo "captured=[$V]"
  • WSL GNU Bash 5.3.0: captured=[<script>: line 2: declare: ZZQ: not found]
  • rubash c9bd0af: captured=[] (diagnostic neither captured nor printed)

Top-level declare -p ZZQ (not in comsub) matches GNU byte-for-byte (<script>: line 2: declare: ZZQ: not found, rc 1). Only the comsub-context diagnostic is dropped, so this looks like the fd-2 endpoint routing family of #167 but for the declare builtin path.

Found while verifying #163 close-out (matrix F1 in target/o2/lang163-matrix.sh, worktree wt/o2-parser). GNU anchor: builtins/declare.def declare_builtin error path sh_notfound/proclists error -> stderr, which inside a comsub is the captured pipe.

Activity

  1. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    Fixed on wt/p3-comsub (026eef32, base 26728da).

    GNU anchor: declare.def:388-404 (pflag loop) → sh_notfound (builtins/common.c:188) → builtin_error (common.c:98-108) vfprintf's to stderr — inside a comsub that fd is inherited (terminal) or, after body-level 2>&1, the capture pipe. GNU never drops it.

    Root cause: execute_declare (src/executor/declare_local.rs) carried a guard from the bashdb hardening commit a69937a (no GNU anchor) that replaced the buffered stderr with an empty Vec whenever stdout_capture was active + print mode + non-zero status — exactly the comsub shape, so the diagnostic vanished both with and without 2>&1. Guard removed; the buffer now routes through write_buffered_builtin_output, which resolves the command's fd-2 endpoint.

    Verification (WSL GNU Bash 5.3.0, LF script both sides): V=$(declare -p ZZQ 2>&1) captures <script>: line 2: declare: ZZQ: not found; plain V2=$(declare -p ZZQ) prints it on real stderr (line 4) — stdout/stderr byte-identical to GNU. Suites comsub/comsub-eof/comsub2/builtins ledger unchanged (25/0/66/7 before and after).

  2. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已在 9ecb59b 落地并关闭(三 commit 已在 issue 评论区有独立说明)。477/477 + 双交叉 + 套件账本零回归。

  3. added
    bug
    area:builtins
    on Oct 17, 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

    area:builtinsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions